Testing Objects for Properties (Lesson)

Tell us what’s happening:
So I realized that I need to change return obj.checkProp to return obj[checkProp] by doing trial and error, I would just like to know why you use bracket notation VS dot notation, sorry if this seems like a stupid question and why I cannot access the data using dot notation.

  **Your code so far**

function checkObj(obj, checkProp) {
// Only change code below this line 
if (obj.hasOwnProperty(checkProp) === true) {
return obj.checkProp;
} else {
return "Not Found";
}
// Only change code above this line
}
  **Your browser information:**

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

Challenge: Testing Objects for Properties

Link to the challenge:

Dot notation is only used when you have the exact, literal name of the property. If you have a variable holding the name of the property, you have to use bracket notation.

1 Like

Got it! thank you so much.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.