I dont get why? 5. Who's in your braket


#1

Why does this work?
var james = {
job: "programmer",
married: false
};

// set to the first property name of "james"
var aProperty = "job"; // I ask this because "job" is a string. How does it know to use "programmer" when you console.log(james[aProperty];

// print the value of the first property of "james"
// using the variable "aProperty"
console.log(james[aProperty]);

But this doesn't
var james = {
job: "programmer",
married: false
};

// set to the first property name of "james"
var aProperty = james.job;

// print the value of the first property of "james"
// using the variable "aProperty"
console.log(james[aProperty]);


#2

This line of code is copying the value, not the property name. It will result in,

console.log(aProperty);            // programmer

We want james[aProperty] to return that. So,

var aProperty = "job";
console.log(james[aProperty]);     // programmer