Who's in Your Bracket?



I don't get this explanation...

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

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???


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

var myProperty = "propName";

so the value of propName is retrieved, which does exist


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