isNaN() function is used to check whether a value is a non-numeric value (NaN). Usage: Pass the value to check as parameter, return true if it is NaN, otherwise return false. Note: isNaN() also returns true for strings, booleans, and null values. Use the Number.isFinite() function to check for a finite number. Use isNaN(value) !== true to check for undefined values.
isNaN() in JavaScript
What is isNaN()
?
isNaN()
is a built-in function in JavaScript that checks whether a value is a non-numeric value, that is, NaN (Not a Number).
Syntax
isNaN(value)
where value
is the value to be checked.
How to use
To use isNaN()
, simply pass the value you want to check as a parameter to the function.
Return value
isNaN()
Returns a Boolean value:
value
is a non-numeric value (NaN), then true
is returned. value
is a numeric value, false
is returned. Notes
The following are some things to note when using isNaN()
:
isNaN()
Also returns true
for strings, booleans, and null
values. Number.isFinite()
function. isNaN()
to check for an undefined
value, use isNaN(value) !== true
. Example
<code class="javascript">console.log(isNaN(NaN)); // true console.log(isNaN(1)); // false console.log(isNaN('abc')); // true console.log(isNaN(true)); // true console.log(isNaN(null)); // true</code>
The above is the detailed content of How to use isnan in js. For more information, please follow other related articles on the PHP Chinese website!