11.9.6 Strict equality comparison algorithm

2010-05-17

Equal to the first part of the regular equality algorithm. The values will never be coerced.

Code: (Meta Ecma)
function StrictEqualityComparison(x, y) {
if (Type(x) != Type(y)) return false;
if (Type(x) == 'undefined') return true;
if (Type(x) == 'null') return true;
if (Type(x) == 'number') {
// nan never matches anything
if (isNaN(x)) return false;
if (isNaN(y)) return false;
// zeroes match (unlike SameValue)
if (x === -0 && y === +0) return true;
if (x === +0 && y === -0) return true;
// now just check values
return x === y;
// note that the specification checks number
// values first, zeroes later, then returns false.
}
if (Type(x) == 'string') return x == y;
if (Type(x) == 'boolean') return x == y;
// x and y are objects...
return x === y; // "refer to same object"
}