Friday, February 23, 2024
 Popular · Latest · Hot · Upcoming
rated 0 times [  154] [ 2]  / answers: 1 / hits: 100011  / 14 Years ago, mon, may 10, 2010, 12:00:00

Just out of curiosity.

It doesn't seem very logical that typeof NaN is number. Just like NaN === NaN or NaN == NaN returning false, by the way. Is this one of the peculiarities of JavaScript, or would there be a reason for this?

Edit: thanks for your answers. It's not an easy thing to get ones head around though. Reading answers and the wiki I understood more, but still, a sentence like

A comparison with a NaN always returns an unordered result even when comparing with itself. The comparison predicates are either signaling or non-signaling, the signaling versions signal an invalid exception for such comparisons. The equality and inequality predicates are non-signaling so x = x returning false can be used to test if x is a quiet NaN.

just keeps my head spinning. If someone can translate this in human (as opposed to, say, mathematician) readable language, I would be grateful.

More From » nan


It means Not a Number. It is not a peculiarity of javascript but common computer science principle.


There are three kinds of operation
which return NaN:

Operations with a NaN as at least one operand

Indeterminate forms

  • The divisions 0/0, ∞/∞, ∞/−∞, −∞/∞, and −∞/−∞

  • The multiplications 0×∞ and 0×−∞

  • The power 1^∞

  • The additions ∞ + (−∞), (−∞) + ∞ and equivalent subtractions.

Real operations with complex results:

  • The square root of a negative number

  • The logarithm of a negative number

  • The tangent of an odd multiple of 90 degrees (or π/2 radians)

  • The inverse sine or cosine of a number which is less than −1 or
    greater than +1.

All these values may not be the same. A simple test for a NaN is to test value == value is false.

[#96832] Thursday, May 6, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 117
Total Questions: 116
Total Answers: 116

Location: Bangladesh
Member since Sat, Jan 23, 2021
3 Years ago
maxinec questions