Javascript boolean object can have logical values either true or false. JavaScript implicitly uses the Boolean object whenever a Boolean data type is converted to a Boolean object.
Variable type Boolean does not support any quotes for example - "true" is not equal to true, "true" will be considered as a string.
Syntax
JavaScript pitfalls: null, false, undefined and NaN
Zero - 0 : Evaluates to false in boolean operations. Always use === when comparing to the number 0.
Empty - "" : Evaluates to false in boolean operations. Always use === when comparing to an empty string.
Undefined : If a variable has not declared or assigned yet then that variable will be given a special undefined value.
NaN : Not a Number, generated when arithmetic operations return invalid results.
Property | Description |
---|---|
constructor | This will returns a reference to the Boolean function that created the object. |
prototype | This prototype property allows you to add properties and methods to an object. |
Here is a list of each function of boolean object with description.
Functions | Description |
---|---|
toSource() | This will returns a string containing the source of the Boolean object; you can use this string to create an equivalent object. |
toString() | This will returns a string of either "true" or "false" depending upon the value of the object. |
valueOf() | This will returns the primitive value of the Boolean object. |