var someObj = { propName: "John" };
function propPrefix(str) {
var s = "prop";
return s + str;
}
var someProp = propPrefix("Name");
console.log(someObj[someProp]);
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36.
Challenge: Accessing Object Properties with Variables
So we have an object called someObj and inside we have the property called propName with value "John". If we use console.log(someObj.propName) or console.log(someObj["propName"] it will log to the console its value- "John". Those are two ways of accessing values of object properties, by dot or bracket notations.
We also have a function, which accepts an argument and returns a string which is equal the value of its local variable s and its argument. If we use console.log(propPrefix("Name")), we will log to the console the string "propName". As you can see we assign to the variable someProp this same string("propName").
In the end we log to the console the value of the property named with the value of someProp, which is found within the someObj, which log "John"