Basic JavaScript - Accessing Object Properties with Dot Notation

Tell us what’s happening:

Describe your issue in detail here.
why are keys that has no special characters writen with quotes?
Isn’t quotes supposed to be omitted when keys has no special characters in them? just asking please.

Your code so far

// Setup
const testObj = {
  "hat": "ballcap",
  "shirt": "jersey",
  "shoes": "cleats"
};

// Only change code below this line
const hatValue = testObj;      // Change this line
const shirtValue = testObj;    // Change this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36

Challenge Information:

Basic JavaScript - Accessing Object Properties with Dot Notation

they can be omitted, but often for style reasons they are kept anyway

1 Like

As said both are valid, but you aren’t very likely to see quoted keys in most code. Prettier removes them as well.

If it was JSON you would have to keep them.


Personally, I would be in favor of removing them from the seed code. Seeing as the example code does not have them either it just looks inconsistent.

Edit: Just to avoid any confusion I made a PR that has removed the quotes from the seed code.

1 Like