Testing Objects for Properties - (Legacy JavaScript Algorithms and Data Structures)

In order to return the property of an object why can I not simply type:

return property;

but instead I must write

return object[property]

?

My 2 main issues are: 1.) why can I not just write the property but must access it with the object ? Is that just how it is ? 2.) Why does it not work with dot notation ?

Below is the code before and after the task was answered.

Modify the function checkObj to test if the object passed to the function parameter obj contains the specific property passed to the function parameter checkProp. If the property passed to checkProp is found on obj, return that property’s value. If not, return Not Found.

function checkObj(obj, checkProp) {
  // Only change code below this line
  return "Change Me!";
  // Only change code above this line
}

After

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
}

Unless the property variable would be re-assigned, it would return just the name of the property, not the value which has specific object under such property.

Using dot notation would attempt to access literally the property with name written after the dot, not the name which might have variable with the same name as the accessed property name.