NaN1. I’ve never dug too deeply into this one, I’ve just known that if you try something like this:
1 2 3 4 5 6 7
The code would always do something else. so I usually found a different way to solve the problem.
NaN has some odd properties:
- It’s a number.
So that’s annoying, but actually lends itself to a very easy solution: if you want to test if a variable is
NaN you can test it like this:
1 2 3 4 5
What struck me about this is that Douglas Adams invented a word for this kind of value:
… a recipriversexcluson, a number whose existence can only be defined as being anything other than itself. Douglas Adams, *The Ultimate Hitchhiker’s Guide to the Galaxy (p. 345). Random House Publishing Group. Kindle Edition. *
If you don’t know,
NaNis a special value meaning “Not a Number” and is used to check if the variable you’re working with actually has numerical data.↩