isNaN
Using
This function determines whether the given value is the special NaN
value (Not-a-Number).
- Returns
true
only if the value is the primitiveNaN
. - Returns
false
for all other values, including anything that is not strictly theNaN
primitive.
Unlike the global isNaN()
function, this version avoids type coercion.
Demo - use JSON
isNaN( )
false
Arguments
Argument | Type | Description | Example |
---|---|---|---|
value | unknown | Can be any type | "text" 2 undefined |
Returns
boolean
— true
if value is primitive NaN
, false
otherwise
Examples
isNaN(NaN);
// true
isNaN(0 / 0);
// true
isNaN(Number('abc'));
// true
isNaN('NaN');
// false
isNaN(42);
// false
isNaN(new Number(NaN));
// false
isNaN(() => NaN);
// false