When accessing a property with the bracket notation as in
foo is treated as the string
An identifier used to access a property with the bracket notation is treated as a string
An identifier used to access a property with the bracket notation is firstly evaluated
CorrectionHere is what's right.
If one uses an identifier, such as a variable name, inside the bracket notation, that identifier is firstly evaluated and the resulting value is used to access the property.
Consider the following code:
domain is an identifier which is resolved before attempting to access a property of
obj and, since there is no definition for
domain, we get a
What one probably wants is to use a string inside the brackets, which can be either a string literal or a variable that contains a string, as demostrated in the next example.