JS中的这段代码给了我一个弹出框,上面写着“i think null is a number”。
if (isNaN(null)) {
alert("null is not a number");
} else {
alert("i think null is a number");
}
我正在使用Firefox 3。是浏览器漏洞吗?
发布于 2018-04-11 12:51:35
isNaN(x)
尝试将传递的参数转换为数字,然后测试该值是否为NaN
。如果参数不能转换为数字,Number(x)
会返回NaN
。因此,如果参数的转换x
的数目NaN
,则返回true;否则返回false。
发布于 2018-04-11 14:16:30
var x = [undefined, NaN, 'blah', 0/0, null, 0, '0', 1, 1/0, -1/0, Number(5)]
x.map( function(n){ return isNaN(parseInt(n))})
[true, true, true, true, true, false, false, false, true, true, false]
https://stackoverflow.com/questions/-100008060
复制相似问题