Hi, maybe a stupid question, but I don’t understand why this code works:
function checkObj(obj, checkProp) {
if (obj.hasOwnProperty(checkProp)) {
return obj[checkProp];
}
return "Not Found";
}
but this code doesn’t:
function checkObj(obj, checkProp) {
if (obj.hasOwnProperty(checkProp)) {
return obj.checkProp;
}
return "Not Found";
}
I thought obj[checkProp] and obj.checkProp would give the same result, but the second answer isn’t accepted. I’d appreciate if someone could explain the difference