This is a dumb question, but when you are assigning the variable: playerNumber to 16, how does it know playerNumber is referring to a property in testObj? How are those two correlated by just assigning 16 to it? I looked back into global/local scope and still couldn’t wrap my head around it. Thanks in advance.
Your code so far
// Setup
const testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};
// Only change code below this line
const playerNumber = 16; // Change this line
const player = testObj[playerNumber]; // Change this line
Challenge: Basic JavaScript - Accessing Object Properties with Variables
Are you asking why you would use a variable instead of a literal value? If so, you will see more examples of using variables with object access later in the curriculum.
There are various reasons why you might need to use a variable, one such being you might not know ahead of time what value you need to use (dynamic runtime access).