Hello, could someone clarify why the first block of code works whilst the second doesn’t? All I’m changing is the notation in the return for the if statement.
============ First Block ============
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {
if (myObj.hasOwnProperty(checkProp) === true) {
return myObj[checkProp];
} else {
return "Not Found";
}
}
checkObj("gift");
============ Second Block ============
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {
if (myObj.hasOwnProperty(checkProp) === true){
return myObj.checkProp;
} else {
return "Not Found";
}
}
checkObj("gift");