Currently, the second example given with lesson, ’ Basic JavaScript: Accessing Object Properties with Variables’ shows a user made method/function used to recreate the property name of ‘propName’. Archaeologist03 you simply made a single expression, " var variableAccesser = ‘propName’ " to recreate the property name. Either way what command or set of characters is telling the javaScript language to make the VALUE of the object’s property appear on the screen via console.log?
The comment from the example (entire example is pasted below), // someProp now holds the value ‘propName’, that makes sense to me. Obviously, Archaeologist03 your single expression gets us there faster.
In both examples, yours Archaeologist03 & said lesson, how does the program “know” to make the object’s value appear?
var someProp = propPrefix("Name"); /* someProp now holds the value 'propName' ........ someProp ONLY has the name of the property */
console.log(someObj[someProp]); /* "John" ...... "John" why "John"? Where in this program have we specifically asked for the VALUE of the object which is of course "John"? console.log(someObj[someProp]); BUT someProp = propName ....... what specifically is telling console.log(someObj[someProp]); to make the object's value appear?
var someObj = {
propName: "John"
};
function propPrefix(str) {
var s = "prop";
return s + str;
}
var someProp = propPrefix("Name"); // someProp now holds the value 'propName'
console.log(someObj[someProp]); // "John"