Possible Duplicate:
JavaScript property access: dot notation vs. brackets?
I’m a total newbie to chrome extensions.
I know Java but Javascript is something entirely different.
I would like to ask what is the difference between localStorage["something"] and localStorage.something?
The square bracket vs dot.
There is no difference. In fact, there is no difference between the two syntaxes in JavaScript as a whole:
The only difference is that certain characters are valid in a string and not in a dot-property name:
Note that both of these methods of storing values in
localStorageare also the same as using the.getItemand.setItemmethods. According to the W3C spec:These items are accessible and mutable via the object property of the same name or by refering to them by name using
.getItemand.setItem. The only difference is that the functions can be overwritten to provide wrappering, e.g., to JSON-ify the object before storage: