JavaScript objects can be accessed using a descriptor (square bracket):
o.foo o['foo']
... This is the same. A square bracket is necessary to access members whose names cannot be used in dotted notation:
o['hello!']
or to access members from a dynamic name:
var name= issomething? 'foo' : 'bar'; o[name]
But for simple o['foo'] you do not need it. The o.foo form is o.foo easier to read, so she thinks it's best to use it. Some programmers coming from other languages ββmay prefer to use square brackets for objects that use βas a match, not as,β but anyway for JS.
(JSlint claims that the shape of the square bracket is also βless efficient,β but if that is the case, the difference is tiny and really not worth the worry.)
source share