I understand this exercise except for one thing. The ** part in the code below is why the solution isn’t accepted. Instead, it’s supposed to be in bracket notation:
return obj[checkProp];
Can we not use dot notation for this? I prefer it, but this is more of a conceptual question. Thanks!!!
function checkObj(obj, checkProp) {
if (obj.hasOwnProperty(checkProp)) {
**return obj.checkProp**;
} else {
return 'Not Found';
}
}
Yeah, you can’t use dot notation like this as what you’re doing is essentially getting the property checkProp from obj. You cannot dynamically access an object’s property using dot notation. This is why the bracket notation exist, so you can dynamically access an object’s property