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

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;
``````

30

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?

Tuesday, June 1, 2021

43

This worked for me:

``````\$get("isAgeSelected ").checked == true
``````

Where `isAgeSelected` is the id of the control.

Also, @karim79's answer works fine. I am not sure what I missed at the time I tested it.

Note, this is answer uses Microsoft Ajax, not jQuery

Tuesday, June 1, 2021

14

check for a remainder when dividing by 1:

``````function isInt(n) {
return n % 1 === 0;
}
``````

If you don't know that the argument is a number you need two tests:

``````function isInt(n){
return Number(n) === n && n % 1 === 0;
}

function isFloat(n){
return Number(n) === n && n % 1 !== 0;
}
``````

Update 2019 5 years after this answer was written, a solution was standardized in ECMA Script 2015. That solution is covered in this answer.

Tuesday, June 1, 2021

80

`NaN` is not equal to anything, not even `NaN`.

Reference at MDN

More detailed SO question and answer

For the authoritative source, see the ECMAScript 5 Official Specification, sections 11.9.1 and 11.9.3:

``````1. If Type(x) is the same as Type(y), then
[...]
c. If Type(x) is Number, then
i. If x is NaN, return false.
ii. If y is NaN, return false.
[...]
``````
Saturday, August 7, 2021

23

`NaN` is a primitive Number value. Just like `1`, `2`, etc.

Saturday, November 6, 2021