js判断空(暂时)
转自:https://zhidao.baidu.com/question/262530264155162685.html
一般判断为空有 null值、undefined值与NaN值
-
判断undefined:
var tmp = undefined;if (typeof(tmp) == "undefined"){ alert("undefined");}
说明:typeof 返回的是字符串,有六种可能:"number"、"string"、"boolean"、"object"、"function"、"undefined"
-
判断null:
var tmp = null;if (!tmp && typeof(tmp)!="undefined" && tmp!=0){ alert("null");}
-
判断NaN:
var tmp = 0/0;if(isNaN(tmp)){ alert("NaN");}
附上全部相等图
≅:松散等于等于检查(==), 比如: "1" == true; [] =="0"
=:全等或恒等全等检查(===)