File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
part9 (Advanced Topics)/client-side-storage Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change
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" ) ;
You can’t perform that action at this time.
0 commit comments