Abstract vs Strict equality
Abstract equality ==
compares for equality after doing any necessary type conversions.
Strict equality ===
compares values to check if they're the same type and if they have the same value.
General rule of thumb is to never use ==
, unless you want convenience when checking if a variable is null
or undefined
.
1 == "1"; // true
1 == [1]; // true
1 == true; // true
0 == ""; // true
0 == "0"; // true
0 == false; // true