最近写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的情况了。