When to put double quotation marks on object's property

Tell us what’s happening:

I don’t understand when to put double quotation marks on property while using the bracket notation or dot notation.
In my code, it doesn’t work when I put double quotation marks and I works when I don’t.

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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36.

Challenge: Testing Objects for Properties

Link to the challenge:

Hello @min999. Welcome to FCC.

checkProp is not a property name. It is a parameter to checkObj function. If you invoke the function, passing in a string which is a property of obj, the passed string will replace the parameter. checkProp is like a variable.

1 Like

In a way, you’re asking the difference between a variable name and a string.

Use this example:

const  planets = {earth:true, mars:true, pluto:false}
//access property using a  string

//access property using a  variable
let usingVariable = "mars"

When you input a string, nothing is replaced.

planets["mars"] will be that, and only that forever.

  • Assign usingVariable="pluto" check what happens.