Reputation: 1669
I'm a beginner of javascript. Here is my question.
Is there any difference between window["property_name"] and window.property_name in javascript?
Upvotes: 1
Views: 121
Reputation: 61885
These forms are identical when name
is a valid JavaScript identifier; in this case the property name is "name"
.
The form with braces is required when the property name is an arbitrary expression (obj[propNameVariable]
) or the property name is not a valid identifier (obj["invalid identifier"]
).
All property names in JavaScript are internally strings.
Upvotes: 4