Home  >  Article  >  Web Front-end  >  How to use isNaN function

How to use isNaN function

不言
不言Original
2019-01-31 15:44:527230browse

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)

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>

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!

Statement:
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
Previous article:How to use NaN attributeNext article:How to use NaN attribute