Learning JavaScript I ran across two methods to find out whether object has defined property.
Method A
if ('propertyName' in object) { }
Method B
if (object.propertyName) { }
Using console.log()
I found out that Method A yields boolean value whereas Method B yields either undefined
or value of the property if defined.
Are there any other differences between these two methods or reasons I should prefer using one over another? If there are no differences I would prefer using Method B since there is no need for using string.