Basic JavaScript - Testing Objects for Properties

Hi there just wondering why this doesnt work

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
}

i got it to work by substituting obj.checkprop with object[checkprop] however if the bracket and dot notations are fundamentally 2 ways of doing the same thing i must be missing something ?

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 (').

This returns the value of the property that is literally called "checkProp"

ahhhaaaaaa i seee :woman_facepalming: very simple , thank you for the clarification, and for the info on proper code formatting

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