Dot operator or[]

Tell us what’s happening:
when i am trying to access myObj class properties using (.)dot operator in the function checkObj
example: return myObj.checkProp it is not returning the value but myObj[checkProp] is returning correct.

Your code so far

// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"

function checkObj(checkProp) {
  return myObj[checkProp];
  else return "Not Found";

// Test your code by modifying these values

**Link to the challenge:**

Yes, that’s the whole reason why the [] notation is supported. Your myObj does not have a checkProp property, so undefined is returned.

1 Like