Tell us what’s happening:
My question isn’t regarding the problem of the exercise, but the example. Notice in the example, after the object is defined, the following entry:
const myDog = "Hunter";
The question is, how does this differ from assigning the string “Hunter” to this variable? How does JS know that we’re referencing a property of the object “dogs”?
BTW the code included is the example, not the exercise…
Your code so far
//Beginning of example
const dogs = {
Fido: "Mutt",
Hunter: "Doberman",
Snoopie: "Beagle"
};
const myDog = "Hunter";
const myBreed = dogs[myDog];
console.log(myBreed);
// End of example
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36
Challenge: Basic JavaScript - Accessing Object Properties with Variables
Link to the challenge: