JavaScript isNaN() Function
The isNaN() function checks whether a value is NaN after converting it to a number. Number.isNaN() is usually the better choice.
Description
The global isNaN() function returns true if the value is NaN after being converted to a number. Because of that conversion, it returns true for values that are not numbers at all, such as 'hello' and undefined. That can be useful for checking user input, but to check whether a value is literally NaN, use Number.isNaN().
The conversion follows the same rules as Number(): empty strings and null become 0, so isNaN('') and isNaN(null) are false, which may not be what you expect when validating input. Checking Number.isNaN(Number(value)) spells out the conversion explicitly.
For validating that a string is a number, also check that it isn't empty, for example value.trim() !== '' && !isNaN(value), or use a regular expression for the exact format you expect.
Syntax
isNaN(value)Parameters
- valueThe value to test. It is converted to a number first.
Return Value
true if the value is NaN after conversion to a number, otherwise false.
Example
Browser Support
The following information will show you the current browser support for the isNaN() function. Hover over a browser icon to see the version that first introduced support for this function.
Desktop





Tablets & Mobile





