前端判断null、undefined与NaN的方法

https://www.cnblogs.com/pangguoming/p/7690816.html
undefined

var tmp = undefined; 
if (typeof(tmp) == "undefined"){
    
     
alert("undefined"); 
}

null

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

NaN

var tmp = 0/0; 
if(isNaN(tmp)){
    
     
alert("NaN"); 
}

Guess you like

Origin blog.csdn.net/weixin_48860638/article/details/121885275