JavaScript object id is syntax?

This is the main question about the JavaScript language (ECMAScript), so I apologize in advance if this is a duplicate (a small search did not reveal my exact question).

In ECMAScript, we can use two basic syntactic forms to get / set the properties of an object, and they seem to have the same effect. Since I do not know better, I will call them the notation "property" and "associative array":

var o = {};
// Property notation.
o.foo = 'Foo'; // (set)
o.foo; // => "Foo" (get)
// Associative array notation.
o['bar'] = 'Bar'; // (set)
o['bar']; // => "Bar" (get)
// They seem to be interchangeable.
o['foo']; // => "Foo"
o.bar; // => "Bar"

Are there any real differences between the two designations? Obviously, an associative array entry allows us to search for dynamically generated keys of an object (and forcibly passes its argument to a string), while property notation uses a literal, but is that the only difference?

+3
1

; .

+5

All Articles