Just out of curiosity.
It doesn\'t seem very logical that typeof NaN is number. Just like NaN === NaN or NaN == NaN returning
It means Not a Number. It is not a peculiarity of javascript but common computer science principle.
From http://en.wikipedia.org/wiki/NaN:
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.