Boolean object is very similar to the Boolean encapsulation class in Java, it has two values: true and false
1. Create a Boolean object
The code copy is as follows: var boo = new Boolean();//The value of boo is not assigned at this time, but its default value is false
var boo = new Boolean(true);
var boo = true/false;
2. The constructor property of the Boolean object is Boolean
example:
The code copy is as follows: var boo = new Boolean();
document.write(boo.constructor==Boolean);
document.write('<br>');
document.write(boo);
The output result is:
true
false
Description: Its constructor property is Boolean
If it is not assigned an initial value, its value is false
3. toString() method returns the string corresponding to the Boolean object
true--->true;
false--->false;
The code copy is as follows: var boo = new Boolean();
document.write(boo);
document.write('<br>');
document.write(boo.toString());
Output:
false
false
The output results of these two methods are the same, somewhat similar to the output of some classes in Java
To view more JavaScript syntax, you can follow: "JavaScript Reference Tutorial" and "JavaScript Code Style Guide". I also hope that everyone will support Wulin.com more.