.hasOwnProperty key word!

Tell us what’s happening:
Describe your issue in detail here.

Hi, I understood the .hasOwnProperty key word, but what I couldn’t understand how obj can check checkProp and they are in same Parenthesis(). also in the question this list of array? checkObj({gift: “pony”, pet: “kitten”, bed: “sleigh”}, “gift”) . from where checkProp restore the list even I didn’t see any variable created.

  **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/91.0.4472.114 Safari/537.36

Challenge: Testing Objects for Properties

Link to the challenge:

Hi, I understood the .hasOwnProperty key word, …

It’s actually a method or a function. A keyword would be something like “var” or “for” or “typeof”.


…but what I couldn’t understand how obj can check checkProp and they are in same Parenthesis().

I’m not sure I understand what you mean. Do you mean this?

function checkObj(obj, checkProp) {

Those are the only place that they are in parentheses together. Those are just two function parameters.

Did you mean this>

if(obj.hasOwnProperty(**checkProp**)){

There, the object (“obj”) has a method called “hasOwnProperty”. All objects inherit this method. That method is being called with the variable “checkProp”. So the method with check it obj has a property that matches the string held in the variable checkProp.

also in the question this list of array? checkObj({gift: “pony”, pet: “kitten”, bed: “sleigh”}, “gift”) . from where checkProp restore the list even I didn’t see any variable created.

I’m not sure I understand what you mean, “array” - I don’t see any arrays here. I don’t see where a list is restored and I don’t see where a variable is created. Please clarify.

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