Skip to content

Commit 7159c60

Browse files
feat: session storage
1 parent 4593ccf commit 7159c60

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
INFO: localStorage
3+
localstorage allows you to store key-value pairs in the browser, with no expiration. The data stays even after the browser/tab is closed.
4+
5+
INFO: Key Features:
6+
1. Presistent unit manually cleared
7+
2. Stores strings only
8+
3. Max size 5-10 MB
9+
4. Synchronous API (blocks main thread)
10+
*/
11+
12+
localStorage.setItem("username", "rafay");
13+
localStorage.getItem("username");
14+
localStorage.removeItem("username");
15+
localStorage.clear(); // clear all keys
16+
localStorage.key(0);
17+
localStorage.length;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
INFO: sessionStorage
3+
Similar to localStorage, but data is only saved for the current tab/session. It's wiped when the tab is closed.
4+
5+
INFO: Key features:
6+
1. lives only during the page session(tab)
7+
2. Same methods & structure as localStorage
8+
3. ALso stores strings only
9+
*/
10+
11+
sessionStorage.setItem("authToken", "12345");
12+
sessionStorage.getItem("authToken");
13+
seesionStorage.removeItem("authToken");

0 commit comments

Comments
 (0)