The JavaScript Boolean represents a boolean primitive type of true or false values. It is very helpful in controlling workflow in conditional statements. In many situations we might have only one of two values:
- YES / NO
- OFF/ ON
- TRUE / FALSE
The Boolean()
function can be used to find out if a variable or an expression is true:
An expression Boolean value is a basis for all JavaScript comparisons and conditions. Everything With a “Value” is considered True.
Everything Without a “Value” is considered False.
JavaScript Booleans – Objects
With the new keyword Boolean values can be defined as objects:
Creating Boolean objects may slow down execution speed. When we used the ==
operator, it means that booleans are equal:
Note: When we used the ===
operator, it means that booleans are not equal
We cannot compare the Boolean objects: