LILLY ROBOT |
The Boolean object represents either a true or false value. The keyword new is used to create a Boolean object.
var nameofVariable=new Boolean();
When you create a new boolean object with nothing inside the parentheses() then the outcome would be false.
Displays
If we put the value 1 inside the parentheses then the outcome would be true.
Displays
If we put a real number inside the parentheses then the outcome would be true.
Displays
If we put a string value inside the parentheses then the outcome would be true, even if you have the value "false".
Displays
However, if you have the value false without the string then the outcome would be false.
Displays
The following values: 0, "", null or NaN would result in false.
Displays
The Boolean object values true and false should not be confused with the primitive boolean values. Look what happens when you use a conditional statement with the value being false.
Displays
Displays
Look what happens when we use the comparison operators to compare the values and type.
Displays
Property | Explanation |
---|---|
constructor() | Returns a reference to the Boolean function that created the object. (returns:function Boolean(){[native code]}) | prototype | The prototype allows you to add properties and methods to an object. In the section Objects you will learn more about prototype. |
Method | Explanation |
---|---|
toString() | The toString() converts a boolean value to a string. | valueOf() | The valueOf() returns the primitive boolean value, which is contained in the Boolean object. |