The Boolean object is a wrapper for the Boolean data type. The Boolean object is used to convert a non-Boolean value to a Boolean value. If a programmer wants to convert a non-Boolean value to a Boolean value, he can use Boolean as a function to perform this task, instead of using a Boolean object to convert a non-Boolean value to a Boolean value.
Other than the above values, any other value passed to the Boolean Object returns true. The programmer must clearly understand that a Boolean object is different from Boolean data type.
When an object’s value is not undefined or null (including a Boolean object whose value is false), it evaluates to true when passed to a conditional statement.
The above concept does not apply for Boolean primitives.
Here the keyword new is used to define the Boolean object.
The above example defines a Boolean Object exforsys.
0, "", false, undefined, NaN, true, any string and so on.
The above example creates two Boolean objects exforsys and sample with initial value as true.
The above example creates two Boolean objects exforsys1 and sample1 with initial value as false.
Properties are the values associated with an object. A Boolean object has only one property, the value of the object – which is either true or false.
valueOf() is used to return the primitive value of a Boolean object.
In the above example, a boolean object exforsys is created with its initial value set as true. The value of the boolean object exforsys is printed using the valueOf() with the boolean object exforsys resulting in a true value.
The toString() method is used to convert a Boolean value to a string and returns the result.
In the above example, a boolean object exforsys is created with its initial value set as true. Then this Boolean value true is converted to a string using the method toString() along with the boolean object exforsys. This is outputs, resulting in a true string.