This article mainly introduces the knowledge points of Boolean objects in javascript, explains the basic usage of Boolean objects, and provides a detailed introduction to the Code. If you are interested, you can refer
Syntax for creating a Boolean object:
New Boolean (value); // Constructor
Boolean (value); // Conversion Function
The parameter value is the value stored by a Boolean object or converted to a Boolean value.
Return Value
When called as a constructor (with the new operator), Boolean () converts its parameters into a Boolean value and returns a Boolean object containing the value.
When called as a function (without the new operator), Boolean () only converts its parameters into an original Boolean value and returns this value.
Note: If the value parameter is omitted or set to 0,-0, null, "", false, undefined, Or NaN, the object is set to false. Otherwise, set it to true (even if the value parameter is a 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, a Boolean value is a basic data type. A Boolean object is a Boolean object that packs a Boolean value. A Boolean object is mainly used to convert a Boolean value to a string's toString () method.
When the toString () method is called to convert a Boolean value to a string (usually called implicitly by JavaScript), JavaScript internally converts the Boolean value to a temporary Boolean object, then, call the toString () method of this object.
The above is the summary of today's javascript learning, and will be updated every day. I hope you will continue to pay attention to it.