Could you explain?

Could you explain?
0

#1

Could you explain why it works chekProp if it is not in myObj? How it return ? How it all works?


#2

checProp is a variable name, that contains the property name. When you are checking the
myObj.hasOwnProperty(checkProp), you are essentially checking if myObj has a property “pet” ( because “pet” is stored in checkProp).

So, what happens is the following. You call the checkobj function with the argument of “pet”. Then the function checks if the argument of pet ( which is stored in checkProp), is a valid property of myObj. If true, checkObj returns the value of property “pet”. If it’s false, it returns “not found”.


#3

Ok, I guess I understand. Thank you.


#4

function checkObj(x) or function checkObj(y) or function checkObj(checkProp) … x,y,checkProp are a name you give to what you put inside the brackets checkOby(“pet”) when calling the function… can be anything you want … just there to let you or whoever uses the function know that a parameter is required eg “pet” and also descriptive so you or they know what is being passed in is referring too.