Home > Web Front-end > JS Tutorial > How to use isNaN function

How to use isNaN function

不言
Release: 2019-01-31 15:44:52
Original
7342 people have browsed it

isNaN function is used to determine whether the value is an illegal number (not a number). If the value is equal to NaN, this function returns true, otherwise it returns false. So in this article we will take a look at the basic usage of the isNaN function.

How to use isNaN function

Basic syntax of isNaN function

isNaN(value)
Copy after login

value indicates the value of NaN to be tested.

The Number.isNaN() method in How to use isNaN function returns true if the passed value is NaN and of type number, otherwise it returns false.

Let’s look at a specific example

The code is as follows

<!DOCTYPE html>
<html>
   <head>
      <title></title>
   </head>
   <body> 
<script type="text/javascript"> 
//当结果为无穷大的方程作为参数传递时
var num=0/0; 
document.write("Output : " + isNaN(num)+"<br/>");
//将数字作为参数传递时
var num=213; 
document.write("Output : " + isNaN(num)+"<br/>");   
//当字符串表示中的数字作为参数传递时。
var num=&#39;213&#39;; 
document.write("Output : " + isNaN(num)+"<br/>");  
//将字符串作为参数传递时.
var test=&#39;hello&#39;; 
document.write("Output : " + isNaN(test)+"<br/>"); 
//当Nan作为参数传递时。
var check=Nan; 
document.write("Output : " + isNaN(check));   
  </script> 
   </body>
</html>
Copy after login

The running result is:

How to use isNaN function

This article is here It’s all over here. For more exciting content, you can pay attention to other related column tutorials on the PHP Chinese website! ! !

The above is the detailed content of How to use isNaN function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template