How do you check that a number is NaN in JavaScript?

Paul D. Waite picture Paul D. Waite · Apr 16, 2010 · Viewed 391.9k times · Source

I’ve only been trying it in Firefox’s JavaScript console, but neither of the following statements return true:

parseFloat('geoff') == NaN;

parseFloat('geoff') == Number.NaN;

Answer

chiborg picture chiborg · Apr 16, 2010

Try this code:

isNaN(parseFloat("geoff"))

For checking whether any value is NaN, instead of just numbers, see here: How do you test for NaN in Javascript?