Understand Booleans

Why is this data type called booleans?

Booleans are named after a mathematician George Boole who did work with logic.

Values

The two boolean values are true and false.

Comparison operators

Identity / strict equality (===)

Returns true if the values are the same including the data type and false otherwise.

console.log(7 === 7); // prints true
console.log(7 === '7'); // prints false
console.log(“hello” === “hello”); // prints true

Non-identity / strict inequality (!==)

Returns false if the values are the same including the data type and true otherwise. The exclamation point you read as not in programming and it flips the boolean.

console.log(7 !== 7); // prints false
console.log(7 !== '7'); // prints true
console.log(“hello” !== “hello”); // prints false

Greater than operator (>)

Returns true if the number is greater on the left and false otherwise.

console.log(7 > 7); // prints false

Less than operator (<)

Returns true if the number is greater on the right and false otherwise.

console.log(6 < 143); // prints true

Greater than or equal operator (>=)

Returns true if the left number is greater or equal to the number on the right and false otherwise.

console.log(17 >= 17); // prints true

Less than or equal operator (<=)

Returns true if the right number is greater or equal to the number on the left and false otherwise.

console.log(89 =< 2); // prints false