When it comes to accessing stored information, utilizing alternatives like the dot operator can be straightforward. However, I’m struggling to grasp the significance of using variables in achieving the same goal.
For instance:
var myObj = {
prop1: "val1",
prop2: "val2"
};
var prop1val = myObj.prop1; // val1
var prop2val = myObj.prop2; // val2
compared with:
var testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};
var playerNumber = 16;
var player = testObj[playerNumber];
Is it simply a matter of personal preference, or are there specific advantages to using each method?