undefined类型是从null派生来的。因此未被定义的变量可以用undefined来判断:
if(temp == undefined ){…}; //true
而:
var temp;
if(temp == undefined ){…}; //false
typeof经常和undefined变量一起使用。typeof运算符返回的都是一个字符串,因此undefined要加引号,作为字符串来判断:
if(typeof temp == undefined ){…}; //error
而:
if(typeof temp ==”undefined”){…};//true
最后
以上就是知性鸡最近收集整理的关于js中if判断undefined问题的全部内容,更多相关js中if判断undefined问题内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复