麻烦老师看看,为啥NULL UNDEFINED 是false 难不成是数值类型吗
来源:3-11 编程练习
YoLo_H
2020-07-18 15:40:34
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var a=null,b=10,c="我是字符串",d="10",e;
console.log(isNaN(a));
console.log(isNaN(b));
console.log(isNaN(c));
console.log(isNaN(d));
console.log(isNaN(e));
</script>
</body>
</html>
1回答
同学你好,转化为数值类型看一下
null转化为数值类型为0,是数字,所以返回值为false 。
e变量未赋值,值为undefined,转化为数值类型为NaN,是非数字,返回值为true,不是false哦。
看一下全部的结果
自己再测试下,祝学习愉快!
相似问题