Basic JavaScript - Testing Objects for Properties

I was doing this challenger and wrote the following code.

function checkObj(obj, checkProp) {
// Only change code below this line

  return obj.checkProp;
  return "Not Found";
// Only change code above this line

after checking that it was incorrect, i changed obj.checkProp into bracket notation and the challenge seemed to be correct.

My question is why is dot notation incorrect here?

Dot notation only works with the exact literal property name, not a variable holding the property name.

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Ah, I understand. Thank you!

I apologize for the format!

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