There is no difference. In fact, there is no difference between the two syntaxes in JavaScript as a whole:
someObj.someProp === somObj["someProp"];
The only difference is that certain characters are valid in a string and not in a dot-property name:
someObj["some-prop"] // valid
someObj.some-prop // this is actually the value of `someObj.some` minus the value of `prop`
Note that both of these methods of storing values in localStorage
are also the same as using the .getItem
and .setItem
methods. According to the W3C spec:
Each Storage object provides access to a list of key/value pairs, which are sometimes called items.
These items are accessible and mutable via the object property of the same name or by refering to them by name using .getItem
and .setItem
. The only difference is that the functions can be overwritten to provide wrappering, e.g., to JSON-ify the object before storage:
localStorage.setItem = function(key, val) {
localStorage[key] = JSON.stringify(val);
}