I'm writing an if statement for this exercise that will make something happen if an object has the specified property. My code was
if (obj.hasOwnProperty(prop)) {
//do this
but the program also works if I change it to
if (obj[prop] {)
I don't understand why the second one works; doesn't obj[prop] just return the value of the property?