localStorage vs sessionStorage
localStorage and sessionStorage are browser features (together called the Web Storage API) that let a website save small amounts of data as key-value strings in the user's browser, usually up to about 5 MB per site. Unlike cookies, this data is not sent to the server with every request.
The difference is how long the data lasts. localStorage keeps data until it is deleted by the site or the user, even after the browser is closed. sessionStorage keeps data only for the current tab and clears it when the tab is closed. Neither should store passwords or tokens that need strong protection, because any JavaScript on the page can read them.
localStorage.setItem("theme", "dark");
localStorage.getItem("theme"); // "dark", even after a restart
sessionStorage.setItem("step", "2");
sessionStorage.getItem("step"); // "2", until this tab is closed
// Objects must be stored as strings
localStorage.setItem("user", JSON.stringify({ id: 1 }));