Imagine there is an object: foo = {"bar": 1}
Is there any benefit to use hasOwnProperty
over dot-syntax to check for bar
property inside foo
object:
if (foo.hasOwnProperty('bar') {
// do something
}
vs
if (foo.bar) {
// do something
}
Also:
- what will hapen if
foo["bar"]
isundefined
? - what if
foo
undefined
?