需求

判断是否为undefined

解决

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

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

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

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

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

相关文章:

  • 2022-12-23
  • 2021-09-18
  • 2021-11-27
  • 2022-12-23
  • 2022-01-19
  • 2022-02-25
  • 2021-09-20
猜你喜欢
  • 2021-06-26
  • 2021-07-21
  • 2022-01-15
  • 2022-12-23
  • 2021-06-08
  • 2022-01-14
  • 2022-12-23
相关资源
相似解决方案