A Rose By Any Other Name …
Basically, isNaN() will test to see if a variable is … well … not a Number.
console.log(isNaN(1)); // false console.log(isNaN("virtuoid")); // true console.log(isNaN("1")); // false console.log(isNaN(0x0a)); // false console.log(isNaN("0x0a")); // false
And That’s It, Right?
Well, yes – and no.
console.log(isNaN(true)); // false console.log(isNaN(null)); // false
console.log(1 + true); // prints 2 console.log(1 + false); // prints 1 console.log(1 + null); // prints 1
It gets better.
console.log(isNaN("")); // prints false
What’s the Takeaway?
Mozilla Developer Network has a great article on isNaN (and NaN in general). If you want to look at tll the weird goings-on with this function, that’s a great place to look.
And now, the video
If reading isn’t your thing, here is a video we made about this subject.
Make sure you follow us on all our social media sites:
Web Tinkerer. No, not like Tinkerbell.