JS中判断null、undefined与NaN的方法

1.判断undefined:

1
2
3
4
var tmp = undefined;
if (typeof(tmp) == "undefined"){
alert("undefined");
}

说明:typeof 返回的是字符串,有六种可能:"number"、"string"、"boolean"、"object"、"function"、"undefined" 

2.判断null:

1
2
3
4
var tmp = null;
if (!tmp && typeof(tmp)!="undefined" && tmp!=0){
alert("null");
}

3.判断NaN:

1
2
3
4
var tmp = 0/0;
if(isNaN(tmp)){
alert("NaN");
}
原文地址:https://www.cnblogs.com/cherryblog/p/8403891.html