码迷,mamicode.com
首页 > 其他好文 > 详细

使用 typeof 来检测对象是否undefined

时间:2018-03-13 22:50:19      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:body   http   变量   pre   class   eof   efi   解决   blog   

需求

判断是否为undefined

解决

使用 typeof 来检测对象是否已定义:

if (typeof Obj !== "undefined" && Obj !== null) 

JavaScript 中, null 用于对象, undefined 用于变量,属性和方法。

对象只有被定义才有可能为 null,否则为 undefined。

参考:http://www.runoob.com/js/js-mistakes.html

使用 typeof 来检测对象是否undefined

标签:body   http   变量   pre   class   eof   efi   解决   blog   

原文地址:https://www.cnblogs.com/52liming/p/8562995.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!