isNaN()
Determines whether a value is NaN after coercing it to a number.
Syntax
isNaN(value)
Returns
boolean — `true` if the value coerces to `NaN`.
Examples
console.log(isNaN(NaN));
console.log(isNaN("hello"));
Output
true
true
console.log(isNaN("123"));
console.log(isNaN(42));
Output
false
false
console.log(isNaN(undefined));
Output
true
Notes
- The global `isNaN()` coerces its argument first, so `isNaN("foo")` is
`true`.
- Prefer `Number.isNaN()`, which does not coerce and only returns `true`
for an actual `NaN`.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 1.0 |
| firefox | 1.0 |
| safari | 1.0 |
| edge | 12 |
| node | 0.10 |