Home > Web Front-end > JS Tutorial > How to use isnan in js

How to use isnan in js

下次还敢
Release: 2024-05-01 09:45:24
Original
724 people have browsed it

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.

How to use isnan in js

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:

  • ifvalue is a non-numeric value (NaN), then true is returned.
  • If 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.
  • To check whether the value is a finite number, you can use the Number.isFinite() function.
  • To use 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>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template