javascript判断undefined值

来源:互联网 发布:大数据的应用案例 编辑:程序博客网 时间:2024/05/16 10:27

JS中判断某个变量是否undefined,不能这样:

if(a == undefined){

}

应使用typeof运算符

if (typeof(a) == "undefined") { 

    alert("undefined"); 

}   

typeof返回值:"number"、"string"、"boolean"、"object"、"function"、"undefined"

0 0