JavaScript Booleans
JavaScript Boolean
A JavaScript Boolean represents one of two values: true or false.
The Boolean() Function
You can use the Boolean() function to find out if an expression (or a variable) is true:
Boolean(10 > 9) // returns true
Comparisons and Conditions
The Boolean value of an expression is the basis for all JavaScript comparisons and conditions.
Everything Without a "Value" is False. The Boolean value of 0 (zero) is false:
var x = 0;
Boolean(x); // returns false
Booleans Can be Objects
Normally JavaScript booleans are primitive values created from literals:
var x = false; But booleans can also be defined as objects with the keyword new:
var y = new Boolean(false);
Do not create Boolean objects. It slows down execution speed. The new keyword complicates the code. This can produce some unexpected results. When using the == operator, equal booleans are equal:
var x = false;
var y = new Boolean(false);
// (x == y) is true because x and y have equal values