Categories
JavaScript Tutorials

Boolean data type

Boolean variables store one of two possible values: either true or false. The term Boolean is named after George Boole (1815–1864), who created an algebraic system of logic. Because it’s named after a person, you generally write it with an initial capital letter. Boolean variables are often used for storing the results of comparisons. You can find out the Boolean value of a comparison or convert any value in JavaScript into a Boolean value by using the Boolean() function. 

For example:

var isItGreater = Boolean (3 > 20);
console.log(isItGreater); 
//false

var areTheySame = Boolean ("tiger" === "Tiger");
console.log(areTheySame); 
//false

In JavaScript, the following values always evaluate to a Boolean false value:

• NaN

• undefined

• 0 (numeric value zero)

• -0

• “” (empty string)

• false