Basic JavaScript - Accessing Object Properties with Variables

Tell us what’s happening:
I just do not understand this code example at all.
I dont understand why is there a function like that,
what is that s= “prop”;
why is it returning s+str
why then “const someProp”,
it feels like theres so much zig zagging just to get the name “John”, so overwhelming…

  **Your code so far**

const someObj = {
  propName: "John"

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

const someProp = propPrefix("Name");
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Basic JavaScript - Accessing Object Properties with Variables

Link to the challenge:

This is example of using variables when dealing with object’s properties.

Yeah, for single John it could be an overkill

But it’s just an example. This approach sometimes useful when you are dealing with big objects.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.