Basic JavaScript - Accessing Object Properties with Variables - eioVjl9Ci3cF3Jc-MZ8U-

Hello, I finished this problem but have an issue with the instructions. How does function(propPrefix) not return s + str when called in const someProp? Does propPrefix combine with Name to form to form propName hence, leading to the statement
console.log(someObj[someProp]); calling the output of the function someObj & someProp leading to the string “John”?

Another way you can use this concept is when the property’s name is collected dynamically during the program execution, as follows:

const someObj = {
  propName: "John"
};

function propPrefix(str) {
  const s = "prop";
  return s + str;
}

const someProp = propPrefix("Name");
console.log(someObj[someProp]);

someProp would have a value of the string propName, and the string John would be displayed in the console.

Note that we do not use quotes around the variable name when using it to access the property because we are using the value of the variable, not the name.

Challenge: Basic JavaScript - Accessing Object Properties with Variables

Link to the challenge:

It does return s + str. s is "prop" and str is "Name", so the return value is “propName”. You can validate that by adding the following console.log statement

const someProp = propPrefix("Name");
console.log(someProp); // displays "propName"

[quote="DigitalAsset, post:1, topic:528784"]
Does propPrefix combine with Name to form to form propName hence, leading to the statement
console.log(someObj[someProp]); calling the output of the function someObj & someProp leading to the string “John”?
[/quote]

Yes

Thank you very much!