Comparison operators

Operators on other types that produce boolean values

Equality comparisons

=== !==

» 1 === 2
false

» 1 !== 2
true

Ordering comparisons

< > <= >=

» 10 < 20
true

» 10 < 10
false

» 10 <= 10
true

» 10 <= (11 - 1)
true

» 100 >= 200
false

Note that you can’t chain comparisons like in math

0 < x < 10

But you can combine two comparisons with logical operators

0 < x && x < 10

You can use the equality operators on booleans

But it’s very rarely needed.

» true === false
false

» true !== false
true

And definitely don’t compare the value of a boolean expression to a boolean literal.

Instead of

x === true

just write:

x

Otherwise why not write?

x === true === true

Or maybe?

x === true === true === true

🤔

And instead of

x === false

or

x !== true

just write:

!x