Syntax for creating Boolean objects:
new Boolean(value); //Constructor
Boolean(value); //Conversion function
Parameter value The value stored by a Boolean object or the value to be converted into a Boolean value.
Return value
When called as a constructor (with operator new), Boolean() will convert its argument to a Boolean value and return a Boolean object containing the value.
If called as a function (without operator new), Boolean() will simply convert its argument to a primitive Boolean value and return this value.
Note: If the value parameter is omitted, or is set to 0, -0, null, "", false, undefined, or NaN, the object is set to false. Otherwise set to true (even if the value argument is the string "false").
var falseObject = new Boolean(false); var result = falseObject && true; alert(result); //true var falseValue = false; result = falseValue && true; alert(result); //false alert(typeof falseObject); //object alert(typeof falseValue); //boolean alert(falseObject instanceof Boolean); //true alert(falseValue instanceof Boolean); //false
Boolean object description
In JavaScript, Boolean values are a basic data type. A Boolean object is a Boolean object that packs a Boolean value. Boolean objects are mainly used to provide the toString() method that converts Boolean values into strings.
When the toString() method is called to convert a Boolean value to a string (usually called implicitly by JavaScript), JavaScript will internally convert the Boolean value into a temporary Boolean object and then call the toString() method of this object. .
The above is today’s summary of JavaScript learning, and it will continue to be updated every day. I hope you will continue to pay attention.