为什么在JS中,isNaN(null)== false?
该isNan()方法在JavaScript中用于检查是否存在未定义的值,或者可以说检查NaN对象。
示例
要检查JavaScript日期是否有效,可以尝试运行以下代码-
<!DOCTYPE html>
<html>
<body>
<script>
var date1, date2;
date1 = new Date("2018/1/1");
if( ! isNaN ( date1.getMonth() )) {
document.write("Valid date1: "+date1);
} else {
document.write("<br>Invalid date1");
}
date2 = new Date("20181/1");
if( ! isNaN ( date2.getMonth() )) {
document.write("<br> Valid date2: "+date2);
} else {
document.write("<br>Invalid date2");
}
</script>
</body>
</html>isNaN(null)==false在语义上是正确的。这是因为null不是NaN。
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短