So there I was, minding my own business, again writing JavaScript tests… when suddenly I wanted to write a test to see what happens if NaN was supplied as a parameter.
NaN
Stands for “Not A Number”. You can get a NaN in a few different ways:
But when checking for NaN, there’s only one way:
isNaN()
isNaN takes the variable and returns a boolean – true if the value is NaN, otherwise false. If you try to check for NaN in any other way:
…It doesn’t work. So make sure you just use isNaN(), ok?