Home >Web Front-end >JS Tutorial >How to use isNaN function
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.
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='213'; document.write("Output : " + isNaN(num)+"<br/>"); //将字符串作为参数传递时. var test='hello'; document.write("Output : " + isNaN(test)+"<br/>"); //当Nan作为参数传递时。 var check=Nan; document.write("Output : " + isNaN(check)); </script> </body> </html>
The running result is:
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!