Javascript Boolean
The Boolean object has two possible values: "true" or "false." The object has an initial value of false if the value parameter is omitted or is 0, -0, null, false, NaN, unknown, or the empty string ("").
Syntax
To make a boolean object, use the syntax below:
var val = new Boolean(value);
Live Demo!
Properties of Booleans
The properties of a Boolean object are listed below:
S No. | Property & Description |
---|---|
1 | constructor The Boolean function that generated the object is returned as a reference. |
2 | prototype You can add properties and methods to an object using the prototype property. |
We'll use a few examples in the following sections to demonstrate the properties of a Boolean object.
Boolean Methods
The methods of a Boolean object are mentioned below, along with their descriptions.
S No. | Method & Description |
---|---|
1 | toSource()
The source of the Boolean object is returned as a string; you can use this string to construct an equivalent object. |
2 | toString()
Depending on the object's value, returns a string that is either "true" or "false." |
3 | valueOf()
The primitive value of the Boolean object is returned. |