您的位置:首页 > Web前端 > JavaScript

js判断undefined类型

2015-08-30 12:49 549 查看

最近写js的时候遇到undefined的情况,按照网上搜的结果大家一致都在用下面的方法来判断

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

alert("undefined");

}

但是这种方法在调试的时候并不管用。调试发现 typeof(reValue)得到的结果是string(在firefox和chrom中使用firebug调试),所以有必要在原来的基础上再加上一个判断

正确的做法是:

if (typeof(reValue) == "undefined" || reValue == "undefined"){

alert("undefined ");

}


这样做就可以避免typeof(reValue)得倒结果为string的情况了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: