Booster
Booster

Reputation: 1669

window["name"] and window.name in javascript

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

Answers (1)

user2864740
user2864740

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

Related Questions