Basic knowledge of Boolean objects in JavaScript programming

Source: Internet
Author: User
This article mainly introduces the basic usage of Boolean objects in JavaScript programming. it is the basic knowledge in JavaScript beginners. if you need it, refer to Boolean) the object is used to convert a non-Boolean value to a Boolean value (true or false ).

Check Boolean value
Check whether the Boolean object is true or false.
Source code example:

​《script》var b1=new Boolean(0);var b2=new Boolean(1);var b3=new Boolean("");var b4=new Boolean(null);var b5=new Boolean(NaN);var b6=new Boolean("false");​document.write("0 is boolean "+ b1 +"
");document.write("1 is boolean "+ b2 +"
");document.write("An empty string is boolean "+ b3 + "
");document.write("null is boolean "+ b4+ "
");document.write("NaN is boolean "+ b5 +"
");document.write("The string 'false' is boolean "+ b6 +"
");《script》​

Test results:

0 is boolean false1 is boolean trueAn empty string is boolean falsenull is boolean falseNaN is boolean falseThe string 'false' is boolean true

Create a Boolean object
The Boolean object represents two values: "true" or "false"
The following code defines a Boolean object named myBoolean:

var myBoolean=new Boolean();

If a Boolean object has no initial value or its value is:

0-0null""falseundefinedNaN

The object value is false. Otherwise, the value is true (even when the independent variable is string "false )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.