Basic JavaScript - Testing Objects for Properties

Tell us what’s happening:
Describe your issue in detail here.
Hello so after spending sometime in this chalenge i come to the conclusion that i had to use brackets , the simple way of accessing a proprierty by the . method does not work and I cannot understand why, Can someone give help me with this ?
I am talking about the return obj[checkProp]; line of code (I used to have return obj.checkProp; and it didnt work.
I have successufully finished the challenge but i could not understand why it didnt work and its bothering me.
Thank you for your time and help.

Your code so far

function checkObj(obj, checkProp) {
  // Only change code below this line
if (obj.hasOwnProperty(checkProp)){
  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/110.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

Try reviewing the following lessons first:

The last challenge directly applies to your question of why.

Another use of bracket notation on objects is to access a property which is stored as the value of a variable
Found it? I did not understand that only with the use of brackets could this propriety be accessed because its stored in the value of a valuable, thank you for your help.

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