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