The HTML Standard specifies the getItem
method as follows:
- If
this
's map
[key] does not exist, then return null.
- Return
this
's map
[key].
Further down from the Storage
interface definition, there is the following that explains what this map
is:
A Storage object has an associated:
map
A storage proxy map.
And then this:
The supported property names on a Storage object storage are the result of running get the keys on storage's map.
This at least confirms that using both getItem
and property access boils down to accessing the map to obtain the value corresponding to the key -- meaning both getItem
method and property access indeed use the same procedure so obtain the same value for a given key.
This is also alluded to from the [non-normative] note closer to the Storage
interface specification, titled "For web developers":
value = storage.getItem (key)
value = storage[key]
Returns the current value associated with the given key, or null if the given key does not exist.
The "HTML Standard" I quoted from, is linked from the Mozilla Developer Network page on Storage
class, among other places, which itself is discoverable through a Google search for localStorage
. I recommend you bookmark the Mozilla Developer Network site and add it as a search engine so you can quickly discover relevant and important information on the Web APIs you use. Don't take MDN for granted though -- if in doubt or as habit, find the relevant standard they attempt to explain, and see if you can read the actual specification, to clear all doubt.