Why does the below dot notation returns undefined and the bracket notation returns correct value?

Tell us what’s happening:

Your code so far


function checkObj(obj, checkProp) {
if (obj.hasOwnProperty(checkProp)) {
  return  obj.checkProp;
  
} else

// Only change code below this line
return "Not Found";
// Only change code above this line
}
checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift")

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36.

Challenge: Testing Objects for Properties

Link to the challenge:

this will return a value only if the object has a property that is literally named checkProp, dot notation can’t be used with variables

1 Like

thanx so much :sweat_smile: