sunny123456

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

JS 判断是否为null

1.判断undefined:

var tmp = undefined;
if (typeof(tmp) == "undefined"){
alert("undefined");
}
说明:typeof 返回的是字符串,有六种可能:"number"、"string"、"boolean"、"object"、"function"、"undefined"

2.判断null:
var tmp = null;
if (!tmp && typeof(tmp)!="undefined" && tmp!=0){
alert("null");
}
3.判断NaN:
var tmp = 0/0;
if(isNaN(tmp)){
alert("NaN");
}

作者:YHCBH
来源:CSDN
原文:https://blog.csdn.net/m0_38035006/article/details/77834910

posted on 2019-11-27 19:14  sunny123456  阅读(5412)  评论(0编辑  收藏  举报