I'm new to JavaScript and I'm trying to test if a property can be accessed by a given object. The function "checkObj" below have arguments "obj" and "checkProp" where "obj " is the object and "checkProp" is the property. I know you can return an object's property with "obj[checkProp]" but why can't I return with "obj.checkProp" using dot notation?
function checkObj(obj, checkProp) {
// Only change code below this line
if (obj.hasOwnProperty(checkProp) == true){
return obj.checkProp;
} else {
return "Not Found";
}
// Only change code above this line
}