Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  3] [ 1]  / answers: 1 / hits: 43105  / 11 Years ago, wed, november 13, 2013, 12:00:00

Why does NaN === NaN return false in Javascript?


> undefined === undefined
true
> NaN === NaN
false
> a = NaN
NaN
> a === a
false

On the documentation page I see this:



Testing against NaN


Equality operator (== and ===) cannot be used to test a value against NaN. Use isNaN instead.



Is there any reference that answers to the question? It would be welcome.


More From » nan

 Answers
6

Strict answer: Because the JS spec says so:




  • If Type(x) is Number, then

    • If x is NaN, return false.

    • If y is NaN, return false.







Useful answer: The IEEE 754 spec for floating-point numbers (which is used by all languages for floating-point) says that NaNs are never equal.


[#74310] Tuesday, November 12, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mireyag

Total Points: 73
Total Questions: 107
Total Answers: 85

Location: Ukraine
Member since Sun, Dec 13, 2020
3 Years ago
mireyag questions
Sun, Aug 15, 21, 00:00, 3 Years ago
Wed, Dec 16, 20, 00:00, 3 Years ago
Tue, Sep 1, 20, 00:00, 4 Years ago
Sun, Jul 5, 20, 00:00, 4 Years ago
;