==
(loose equality) and ===
(strict equality).==
.===
, which is a more strict equality test.Essentially ==
does a “type conversion” before comparing. This leads to some weird behavior (for instance it is no longer transitive). Some examples:
0 == "0" // true
0 == "" // true
"" == "0" // false
0 === "0" // false
false == "false" // false
0 == false // true
Two objects are only equal if they are literally the same object:
var o = { foo: 2 }; var o2 = { foo: 2 };
o == o2; // false
o == o; // true
Exception: There is one case where using loose equality works well: If you want to capture both “undefined” and “null”. So
o == null
is going be true both wheno
is undefined and when it is null.