Late answer but felt to add some points here.
Session storage will be available for specific tab where as we can use Local storage through out the browser. Both are default to same origin and we can also store values manually with key, value pairs (value must be string).
Once tab (session) of the browser is closed then Session storage will be cleared on that tab, where as in case of Local storage we need to clear it explicitly. Maximum storage limit respectively 5MB
and 10MB
.
We can save and retrieve the data like below,
To Save:
sessionStorage.setItem('id', noOfClicks); // localStorage.setItem('id', noOfClicks);
sessionStorage.setItem('userDetails', JSON.stringify(userDetails)); // if it's object
To Get:
sessionStorage.getItem('id'); // localStorage.getItem('id');
User user = JSON.parse(sessionStorage.getItem("userDetails")) as User; // if it's object
To Modify:
sessionStorage.removeItem('id'); // localStorage.removeItem('id');
sessionStorage.clear(); // localStorage.clear();
P.S: getItem()
also return back the data as string and we need convert it into JSON format to access if it's object.
You can read more about Browser Storages here..