Testing Objects for PropertiesPassed (link: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties )

Tell us what’s happening:
in tuitorial says that .hasOwnProperty(“parameter”) function’s parameter shall be used
with quotes.
But, the correct answer accepts it without quote?

Your code so far


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
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0.

Challenge: Testing Objects for Properties

Link to the challenge:

Correct form would be parameter without quotes, but how and why?

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

            }

remember that characters surrounded by quotes are strings

and that when you use a variable, the variable will be evaluated to the value it contains

so if you do

let a = "name";
obj.hasOwnProperty(a); // this is checking if the object has property "name" because the variable a contains that string