1// Save data to sessionStorage
2sessionStorage.setItem('key', 'value');
3
4// Get saved data from sessionStorage
5let data = sessionStorage.getItem('key');
6
7// Remove saved data from sessionStorage
8sessionStorage.removeItem('key');
9
10// Remove all saved data from sessionStorage
11sessionStorage.clear();
12
1 var setsession = window.sessionStorage.setItem("animals", "cat");
2 var getsession = window.sessionStorage.getItem("animals");
3 console.log(getsession);
1sessionStorage is like localStorage
2except that it is cleared when the page session ends meaning when you close
3your chrome tab or any other browser tab
4
5usage methods
6
7// Save data to sessionStorage
8sessionStorage.setItem('key', 'value');
9
10// Get saved data from sessionStorage
11let data = sessionStorage.getItem('key');
12
13// Remove saved data from sessionStorage
14sessionStorage.removeItem('key');
15
16// Remove all saved data from sessionStorage
17sessionStorage.clear();
1localStorage.setItem('name', 'Bob') // make/set a key/value
2var username = localStorage.getItem('name') // get the key
3console.log(username) // log the key
4// This data will be saved even after you close the page