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 )!