=== (strict equality) compares without converting types, so different types are never equal. == (loose equality) first converts both sides to a common type, then compares.
The == conversion rules cause surprises. These are all true:
'' == 0'0' == 0[] == false
Yet '' == '0' is false.
Both operators compare objects by reference. Two different objects with the same contents are not equal under either one.
Edge cases:
NaNis not equal to anything, not even itself, under both operators.null == undefinedis true. But neither is loosely equal to0or''.Object.isis like===, with two differences:Object.is(NaN, NaN)is true, andObject.is(0, -0)is false.
Use === by default. The one common, intentional use of == is x == null, which checks for both null and undefined.
===does no type conversion.==converts types first.- Both compare objects by reference.
NaNis never equal to itself. UseNumber.isNaNorObject.isto check for it.null == undefinedis true, but neither one equals0.- Use
===by default.x == nullis the accepted exception.
Read more