【js语法】isNaN()

编程练习

用isNaN()函数检测下我们学过的数据类型是不是数值类型吧!

需要判断的数据如下:

null,10,“我是字符串”,“10“,undefined

任务

第一步:在<script></script>标签里定义几个变量,值分别为:null,10,“我是字符串”,“10“,undefined

第二步:使用isNaN()来判断下他们是否是数值,一定要注意:isNaN()返回的是false,表示就是数值,返回的是true,表示就是非数值

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>数据类型之isNaN</title>
</head>
<body>
<script>
//补充代码
var a=null,b=10,c="我是字符串",d="10",e="undefined";
console.log (isNaN (a));
console.log (isNaN (b));
console.log (isNaN (c));
console.log (isNaN (d));
console.log (isNaN (e));
</script>
</body>
</html>

结果

猜你喜欢

转载自blog.csdn.net/qq_39799094/article/details/108975523