Ahh… there are some very wrong, very old YouTube demos leading a lot of people to wrong answers on this problem.
This is very confusing formatting. Lets look at something clearer:
function checkObj(obj, checkProp) {
if (checkObj.hasOwnProperty(checkProp)) {
return checkObj[checkProp];
} else if (checkObj.hasOwnProperty(obj)) {
return checkObj[obj];
} else {
return "Not Found";
}
};
console.log(checkObj("gift"));
If you are seeing formatting like that on YouTube, I would totally ignore that YouTube content creator. That’s some weird stuff.
This line:
checkObj.hasOwnProperty(checkProp)
says "check if the function checkObj has the property checkProp. This isn’t what you want.
This line:
checkObj.hasOwnProperty(obj)
says "check if the function checkObj has the property obj. This is even less of what you want. the argument to hasOwnProperty needs to be a string, not an object.
You need to check if the objectobj has the propertycheckProp.