From 5d832d90ecae8f2acfa6db08f2420af44132d385 Mon Sep 17 00:00:00 2001 From: Sergei Date: Tue, 25 Jan 2022 19:35:03 +0300 Subject: [PATCH] Fixes localStorage spec link --- 6-data-storage/02-localstorage/article.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/6-data-storage/02-localstorage/article.md b/6-data-storage/02-localstorage/article.md index 3b4df0a6..412f44c1 100644 --- a/6-data-storage/02-localstorage/article.md +++ b/6-data-storage/02-localstorage/article.md @@ -64,6 +64,7 @@ delete localStorage.test; That's allowed for historical reasons, and mostly works, but generally not recommended, because: 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: + ```js run let key = 'length'; localStorage[key] = 5; // Error, can't assign length @@ -119,7 +120,6 @@ for(let key of keys) { The latter works, because `Object.keys` only returns the keys that belong to the object, ignoring the prototype. - ## Strings only 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 alert( JSON.stringify(localStorage, null, 2) ); ``` - ## sessionStorage 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 ## Storage event -When the data gets updated in `localStorage` or `sessionStorage`, [storage](https://www.w3.org/TR/webstorage/#the-storage-event) event triggers, with properties: +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: - `key` – the key that was changed (`null` if `.clear()` is called). - `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_ ## Summary Web storage objects `localStorage` and `sessionStorage` allow to store key/value in the browser. + - Both `key` and `value` must be strings. - The limit is 5mb+, depends on the browser. - They do not expire.