freeCodeCamp Challenge Guide: Accessing Object Properties with Dot Notation

Accessing Object Properties with Dot Notation


Solutions

Solution 1 (Click to Show/Hide)
var testObj = {
  hat: "ballcap",
  shirt: "jersey",
  shoes: "cleats"
};

// Only change code below this line

var hatValue = testObj.hat; // Change this line
var shirtValue = testObj.shirt; // Change this line
2 Likes

Spoiler with a question.

prop1 does not equate to “prop1” in my brain, is there a reason why it is explained this way that gets around identity property (a=a)? Earlier this is clearer and specifically addressed as a distinction. Here it just seems assumed… is there a reason why?

edit:
“Note that we do not use quotes around the variable name when using it to access the property because we are using the value of the variable, not the name” -FCC (2 challenges later)

7 Likes

// Setup
var testObj = {
hat: “ballcap”,
shirt: “jersey”,
“shoes”: “cleats”
};

// Only change code below this line

var hatValue = testObj.hat; // Change this line
var shirtValue = testObj.shirt; // Change this line

5 Likes