The Boolean object is a wrapper object that holds a primitive Boolean value. | |
The Boolean object provides a method for converting the value to a string. | |
A primitive boolean can have only one of two states: true or false. | |
JavaScript uses the number 1 to represent true and 0 to represent false but provides the toString() method to return the strings "true" and "false". | |
A Boolean object is created with the Boolean() constructor and the new operator or by the Boolean() function. | |
Constructor: | |
| |
value is the value to be converted to a Boolean value and stored in the object. | |
The values null, NaN, "" (empty string), and 0 (zero) are converted to false. | |
All other values (including the string "false") are converted to true. | |
If the new operator is used, the new Boolean object is returned. | |
If the Boolean() function is used, the primitive Boolean value is returned. | |
Method toString() returns a string representation of the primitive Boolean value. | |
If the object contains true, the string "true" is returned. | |
If the object contains false, the string "false" is returned. | |
|