I am on Accessing Object Properties with Variables module and I am confused. Why does the console print “Hunter”? This is the way I read it from what I read:
The variable dogs is created, and inside that variable, there is
Fido: which will produce the string “Mutt”
Hunter: which will produce the string “Doberman”
Snoopie: which will produce the string “Beagle”
Then, the string “Hunter” is assigned a variable myDog
Then, the variable dogs and the variable myDog is assigned a new variable, myBreed.
This lesson, and the previous three on objects are extremely important so I would suggest you review them until you understand every single detail of the examples and the code.
Remember that objects are a group of key-value pairs. In this case, dogs is an object with 3 key-value pairs. “Fido” is the key to the value “Mutt”, “Hunter” is the key to the value “Doberman”, and “Snoopie” is the key to the value “Beagle”.
To access the values inside the object, you need to provide the key. That can be done in two ways, dot notation (two lessons back) or bracket notation (this and the previous lesson).
When you know the literal value of the key ahead of time you can use dot notation.
Notice that when you pass the literal string inside the brackets, it works exactly the same as dot notation.
The powerful thing with bracket notation is that the expression is evaluated, so we can do things like use variables or calculations to create the key string.