Dot notation looks for a specific property called “checkProp”, where bracket notation looks for a property called the value of the “checkProp” variable.
It took me five minutes to figure out that obj.checkProp would return undefined as it was looking for the the value “checkProp” in obj that does not exist.
return obj[checkProp]; uses the value stored inside checkProp so it would actually look for obj.gift and return pony etc.
i find console.log(variable in here); very useful to find the issues in my code
var myobj = {gift: "pony", pet: "kitten", bed: "sleigh"}
function checkObj(myobj, checkProp) {
var result ="";
if (myobj.hasOwnProperty(checkProp))
{
result = myobj.checkProp;
console.log("Found");
return result ;}
else {
return "Not Found";}}
checkObj(myobj, "gift")