# Not why, but HOW is NaN not equal to NaN in Javascript?

I understand the reasoning behind this. I'm curious about the technical implementation. Having trouble finding this somewhere.

My theory is that as soon as the left NaN is evaluated in any comparison, it automatically returns false without performing the comparison at all. Is this correct?

Possible duplicate of What is the rationale for all comparisons returning false for IEEE754 NaN values?

*"How is NaN not equal to NaN in JavaScript"* - Simple, `NaN`

simply means not a number. Take this example: `Math.sqrt(-1)`

results in `NaN`

. `parseInt("car")`

also results in `NaN`

. In no way shape or form are they remotely equal, but rather they are represented by `NaN`

because neither one are numbers. `NaN`

does not imply a type but rather only explicitly states that the value is *not a number*. It could be any number of types, but the conversion to the type of `Number`

failed and therefore the returned value is *not a number*...

@MichaelJasper OP is *specifically* asking *how* the logic is implemented, not *why* - "What is the rationale" is about "why", not "how".

### 1 Answer

Yes - if both types are the same, and they are numbers, then if the left one is `NaN`

, then the result is `false`

, without checking the value of the right one:

https://www.ecma-international.org/ecma-262/6.0/#sec-strict-equality-comparison

7.2.13 Strict Equality Comparison

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

If Type(x) is different from Type(y), return false.

If Type(x) is Undefined, return true.

If Type(x) is Null, return true.

If Type(x) is Number, then

If x is NaN, return false.If y is NaN, return false.

If x is the same Number value as y, return true.

If x is +0 and y is ?0, return true.

If x is ?0 and y is +0, return true.

Return false.

...

It's implemented per IEEE 754: stackoverflow.com/questions/1565164/…