re: 10 Challenging JavaScript Quiz Questions and Answers VIEW POST

re: NaN === NaN // false, The identity evaluation algorithm (IEA) rule 4 Operands are the same type (numbers), but the IEA rule 4 indicates than nothin...

The page you've referenced is mostly correct, but they're a bit confused on terminology, and have made things rather more complicated that necessary.

See: ecma-international.org/publication...

7.2.16 Strict Equality Comparison
The comparison x === y, where x and y are values, produces true or false. Such a comparison is performed as follows:

  1. If Type(x) is different from Type(y), return false.
  2. If Type(x) is Number or BigInt, then a. Return ! Type(x)::equal(x, y).
    1. Return ! SameValueNonNumeric(x, y).

Now, what this means is that some things with the same identity compare false with ===, and some things with different identities compare true with ===.


NaN === NaN is false

-0 === 0 is true

Which means that it is not checking the identity of the operands -- it is computing a kind of equality (using the strict equality comparison).

So, === is not an identity operator, and for these reasons is not called an identity operator in the language specification.

It's just some confused people on the internet who are making that into a popular mistake. :)

Code of Conduct Report abuse