JavaScript has both strict and type-converting comparisons:
- Strict comparison (using
3
equal signs like ===) checks for value equality without allowing for coercion - Abstract comparison (e.g. ==) checks for value equality with coercion allowed

Here are some simple equality rules:
- If either value (aka side) in a comparison could be the
true
orfalse
value, avoid==
and use===
. - If either value in a comparison could be of these specific values (
0
,, or
[]
-- empty array), avoid==
and use===
. - In all other cases, you're safe to use
==
. Not only is it safe, but in many cases it simplifies your code in a way that improves readability.
xxxxxxxxxx
var a = "42";
var b = 42;
a == b; // true
a === b; // false
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment