HTML and CSS Reference
In-Depth Information
You can compare two values for equality
with these operators:
==
EQUAL
Returns
true
if both
operands are the same
Returns
true
if the
operands are different
!=
NOT
EQUAL
Note that if you begin comparing things of
different types, you may get unexpected
results.
Because JavaScript helpfully converts
types for you, the equality operators aren't
always reliable.
Returns
true
if the
operands are the same
type and have the
same value
===
IDENTICAL
Again, if you compare things of different
types, you may get unexpected results. In
the example here,
2 == "2"
(comparing an
integer with a string) evaluates to
true
,
since JavaScript converts the integer 2 to
a string
"2"
before comparison. But
2 ===
"2"
evaluates to
false
because an integer is
not a string.