Boolean Logic:

Comparison operations:

Mathematical comparisons

These give a Boolean value (true or false) depending on the outcome of the comparison operation.

Operation: True when:
a < b a is less than b
a <= b a is less than or equal to b
a > b a is greater than b
a >= b a is greater than or equal to b
a == b a is equal to b
a != b a is not equal to b
a === b a is equal to b and both are the same type (strict equality)
a !== b a is not equal to b and both are the same type (strict inequality)

Examples:
1 < 2 is true 2 < 1 is false
2 == 3 is false 2 != 3 is true
5 === 5 is true "5" === 5 is false (types do not match)

We can also compare strings in JavaScript. Strings are compared alphabetically, i.e. "a" comes before "b" and so on. Capital letters come before lower case letters, i.e. "Z" < "a".

"abb" < "abc" is true
"abc" > "Z" is true

Numbers are type converted into strings for comparison against other strings, use === or !== to avoid type conversion.

"2" <= 2 is true "3" > 2 is true
"2" == 2 is true "2" === 2 is false

Boolean Operators and Truth Tables:

A truth table is a table of all inputs (represented as 0 for false and 1 for true) and the resulting output of the operation. We will use truth tables to describe the Boolean operations:

NOT NOT a is the reverse of a, i.e. true if a is false and false if a is true. In JavaScript ! is the Logical NOT operator.
Example: ! a
a !a
0 1
1 0
AND a AND b is true if and only if both a and b are true. In JS && is the Logical AND operator.
Example: a && b
a b a && b
0 0 0
0 1 0
1 0 0
1 1 1
OR a OR b is true if either a or b is true. In JS || is the Logical OR operator.
Example: a || b
a b a || b
0 0 0
0 1 1
1 0 1
1 1 1
XOR a XOR b is true only if a and b are not the same. This is essentially the != (not equal) operator.
a b a != b
0 0 0
0 1 1
1 0 1
1 1 0

Operations are combined left to right. Use () to force the order of evaluation.

a && b || c (a && b) || c != a && (b || c)

a b c (a && b) || c a && (b || c)
0 0 0 0 0
0 0 1 1 0
0 1 0 0 0
0 1 1 1 0
1 0 0 0 0
1 0 1 1 1
1 1 0 1 1
1 1 1 1 1

More examples:

(5 < 4) || (4 < 5) is true
(4 < 5) && (3 < 3) is false