Detecting an undefined object property

后端 未结 30 2915
花落未央
花落未央 2020-11-21 04:43

What\'s the best way of checking if an object property in JavaScript is undefined?

30条回答
  •  悲哀的现实
    2020-11-21 05:39

    Compare with void 0, for terseness.

    if (foo !== void 0)
    

    It's not as verbose as if (typeof foo !== 'undefined')

提交回复
热议问题