Javascript Boolean object

Source: Internet
Author: User

1. Understand Boolean objects

Boolean objects are also Boolean objects, indicating logic, true and false.

2. Create a Boolean object

1 <script language = "javascript"> 2 // Boolean objects are also Boolean objects, indicating logic. syntax for true and false 3/* Creating Boolean objects: 4 // constructor 5 new Boolean (value); 6 // Conversion Function 7 Boolean (value); 8 prompt: The value parameter can be the value to be converted to a Boolean object, it can also be the value stored in a Boolean object. 9 */10 document. write (typeof (new Boolean (1) + "<br/>"); // using the constructor (new Keyword), the output of an object containing a Boolean value is obtained: object11 document. write (typeof (Boolean (1) + "<br/>"); // use the Conversion Function to obtain a Boolean value. Output: boolean12 13 // -------------------------- note ----------------------- 14 // if the value parameter is set to 0,-0, null, "", false, undefined, Or NaN, or omit this parameter, [set this Boolean object to false], and vice versa. 15 document. write (new Boolean (0) + "<br/>"); // false16 document. write (new Boolean (-0) + "<br/>"); // false is followed by 17 documents. write (new Boolean (null) + "<br/>"); 18 document. write (new Boolean ("") + "<br/>"); 19 document. write (new Boolean (false) + "<br/>"); 20 document. write (new Boolean (undefined) + "<br/>"); 21 document. write (new Boolean (NaN) + "<br/>"); 22 document. write (new Boolean () + "<br/>"); 23 24 //------------- ----------- Note 2 ----------------------- 25 // although the Boolean object is set to false, it is still true: 26 var boo = new Boolean (false) in the if judgment ); // set the Boolean object to false27 if (boo) {document. write (1);} 28 else {document. write (2);} 29 // result output: 130 // resolution: the reason is that although boo is an object set to false, boo is a non-empty object, so it is considered meaningful. Return true and the result is true. This is irrelevant to the Boolean value contained in the obj1 object. 31 </script>

3. Boolean attribute | Boolean Method

Boolean objects support the prototype attribute to add or redefine the attributes and methods of objects. For more information, see prototype attributes and methods of JavaScript objects. ---5idev.com

Related Article

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.