Who's in Your Bracket?


#1

https://www.codecademy.com/courses/objects-ii/0/5?curriculum_id=506324b3a7dffd00020bf661

I don't get this explanation...


var someObj = {propName: someValue};
var myProperty = "propName";
someObj[myProperty];

first line: var someObj = {propName: someValue};
- creates new object that gets property 'propName' assigned to it with the value "someValue"

second line: var myProperty = "propName";
- creates a completely new variable that gets a string ("propName") assigned to it.

third line: someObj[myProperty];
- retrieves the value of 'myProperty', HOWEVER: how can 'someObj' access the property 'myProperty' when it did nowhere get assigned to it before???


#2

but myProperty is a variable, which you defined on line 2:

var myProperty = "propName";

so the value of propName is retrieved, which does exist


#3

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