Boolean type object of javascript
- 2021-06-28 06:13:34
- OfStack
The Boolean object is similar to the Boolean encapsulation class in Java, having two values: true and false
1. Create an Boolean object
var boo = new Boolean();// Is not correct at this time
boo Is assigned, but its default value is
false
var boo = new Boolean(true);
var boo = true/false;
2. The constructor attribute of the Boolean object is Boolean
Example:
var boo = new Boolean();
document.write(boo.constructor==Boolean);
document.write('<br>');
document.write(boo);
The output is:
true
false
Note: Its constructor attribute is Boolean
If it is not given an initial value, its value is false
3. The toString () method, which returns the string corresponding to the Boolean object
true---
>
true;
false---
>
false;
var boo = new Boolean();
document.write(boo);
document.write('<br>');
document.write(boo.toString());
Output:
false
false
The output of these two methods is like 1, which is somewhat similar to the output of some classes in Java