==
)null == undefined // => true
NaN == NaN // => false
There can be multiple steps
/* 1 */ 1 == "" // coerce String -> Number
/* 2 */ 1 == 0 // => false
/* 1 */ "1" == true // coerce Boolean -> Number
/* 2 */ "1" == 1 // coerce String -> Number
/* 3 */ 1 == 1 // => true
When using the strict equality operator (===
), types are not coerced.
To put it another way, two expressions are strictly equal if they have the same type and the same value.
Objects (including Arrays and Functions) are compared by reference. Two references are equal only if they reference the same object.
[1] === [1] // => false
var a = [1];
var b = a; // b is now a reference to the same object as a
a === b // => true
.toString
method is called on the Object