Boolean Object Overview
The Boolean object represents two values: "true" or "false". In general, it is used to convert a non-Boolean value to a Boolean value.
Creating a Boolean Object
To create a Boolean object, use the new keyword and assign the result to a variable.
The following example creates a Boolean named 'myBoolean':
var myBoolean = new Boolean();
Note: If the Boolean object has no initial value or if it is 0, -0, null, "", false, undefined, or NaN, the object is set to false. Otherwise it is true (even with the string "false")
Properties
Property | Description |
---|---|
constructor |
Returns the function that created the object's prototype |
prototype |
Allows addition of properties and methods to an object |
Methods
Method | Description |
---|---|
toString() |
Converts a Boolean value to a string, and returns the result |
valueOf() |
Returns the primitive value of a Boolean object |