Skip to main content

isNaN()

isNaN(value): boolean

Checks if value is NaN.

DEPRECATED

Use Number.isNaN() directly instead.


Parametersโ€‹

value: unknownโ€‹

The value to check.


Returns: booleanโ€‹

true if value is NaN, else false.


See Alsoโ€‹


Sinceโ€‹

2.0.0


Also known asโ€‹

isNaN (Lodash, es-toolkit) ยท โŒ (Remeda, Radashi, Ramda, Effect, Modern Dash, Antfu)


Exampleโ€‹

// โŒ Deprecated approach
isNaN(NaN); // => true
isNaN(undefined); // => false (unlike global isNaN)
isNaN('NaN'); // => false (unlike global isNaN)

// โœ… Recommended approach
Number.isNaN(NaN); // => true
Number.isNaN(undefined); // => false
Number.isNaN('NaN'); // => false

How it works?โ€‹

Checks if value is NaN.

Difference from Global isNaNโ€‹

Common Checksโ€‹

ValueResult
NaNcheckmark true
undefinedcross false
'NaN'cross false
nullcross false
42cross false

warning Deprecated: Use Number.isNaN() directly.


Use Casesโ€‹

Check NaN value ๐Ÿ“Œโ€‹

Check if value is NaN (Not a Number).

Number.isNaN(NaN);        // true
Number.isNaN(undefined); // false
Number.isNaN('hello'); // false

Validate parsed numbersโ€‹

Check if parsing produced valid number.

const parsed = parseFloat(userInput);
if (Number.isNaN(parsed)) {
console.log('Invalid number');
}