javascript - Is there any way to distinguish between an unset property and a property set to undefined? -
this question has answer here:
- checking if key exists in javascript object? 13 answers
say have object testobject = {a: undefined}
. if console.log(testobject.a)
, undefined. same happens if console.log(testobject.b)
, doesn't exist. there way in javascript distinguish between a
, b
here? ask out of curiosity, have no use case.
hasownproperty()
method returns boolean indicating whether object has specified property own (not inherited) property.
in given case -
testobject = {a: undefined}; testobject.hasownproperty('a') //true testobject.hasownproperty('b') //false
Comments
Post a Comment