java中isnan函数
Prerequisite: NaN property in JavaScript
先决条件: JavaScript中的NaN属性
isNaN()函数 (isNaN() function)
isNaN() function is a predefined global function in JavaScript and it is used to check whether a given value is an illegible number or not. If the given value is an illegal number - it returns true and if the given value is a legal number – it returns false.
isNaN()函数是JavaScript中预定义的全局函数,用于检查给定值是否为难以辨认的数字。 如果给定值是非法数字-则返回true ;如果给定值是合法数字-则返回false 。
Example:
例:
<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>
var num1 = 10;
var num2 = parseInt("Hello");
//printing the values
document.write("num1: " + num1 + "<br>");
document.write("num2: " + num2 + "<br>");
//checking illegal value using isNaN() function
if(isNaN(num1))
document.write("num1 is an illegal number <br>");
else
document.write("num1 is a legal number <br>");
if(isNaN(num2))
document.write("num2 is an illegal number <br>");
else
document.write("num2 is a legal number <br>");
</script>
</body>
</html>
Output
输出量
num1: 10
num2: NaN
num1 is a legal number
num2 is an illegal number
翻译自: https://www.includehelp.com/code-snippets/isNaN-function-with-example-in-javascript.aspx
java中isnan函数