You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: 6-data-storage/02-localstorage/article.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -64,6 +64,7 @@ delete localStorage.test;
64
64
That's allowed for historical reasons, and mostly works, but generally not recommended, because:
65
65
66
66
1. If the key is user-generated, it can be anything, like `length` or `toString`, or another built-in method of `localStorage`. In that case `getItem/setItem` work fine, while object-like access fails:
The latter works, because `Object.keys` only returns the keys that belong to the object, ignoring the prototype.
121
122
122
-
123
123
## Strings only
124
124
125
125
Please note that both key and value must be strings.
@@ -148,7 +148,6 @@ Also it is possible to stringify the whole storage object, e.g. for debugging pu
148
148
alert( JSON.stringify(localStorage, null, 2) );
149
149
```
150
150
151
-
152
151
## sessionStorage
153
152
154
153
The `sessionStorage` object is used much less often than `localStorage`.
@@ -180,7 +179,7 @@ That's exactly because `sessionStorage` is bound not only to the origin, but als
180
179
181
180
## Storage event
182
181
183
-
When the data gets updated in `localStorage` or `sessionStorage`, [storage](https://www.w3.org/TR/webstorage/#the-storage-event) event triggers, with properties:
182
+
When the data gets updated in `localStorage` or `sessionStorage`, [storage](https://html.spec.whatwg.org/multipage/webstorage.html#the-storageevent-interface) event triggers, with properties:
184
183
185
184
- `key` – the key that was changed (`null` if `.clear()` is called).
186
185
- `oldValue` – the old value (`null` if the key is newly added).
@@ -221,6 +220,7 @@ Modern browsers also support [Broadcast channel API](mdn:/api/Broadcast_Channel_
221
220
## Summary
222
221
223
222
Web storage objects `localStorage` and `sessionStorage` allow to store key/value in the browser.
0 commit comments