Detecting an undefined object property

后端 未结 30 2842
花落未央
花落未央 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:45

    The solution is incorrect. In JavaScript,

    null == undefined
    

    will return true, because they both are "casted" to a boolean and are false. The correct way would be to check

    if (something === undefined)
    

    which is the identity operator...

提交回复
热议问题