js localstorage
The main purpose of localStorage is to permanently store small amounts of data in the user's browser so that the data is remembered even if the page is refreshed or the browser is closed and reopened.
How does it work
You save the data once (localStorage.setItem). The data remains even if the user closes and reopens the browser. It remains even if the computer is restarted. However, if the user clears the browser history / website data, or if you use localStorage.removeItem or localStorage.clear() in code, the data is deleted.
Example
// Save
localStorage.setItem("username", "Metehan");
// Even if you turn it on and off it remains the same.
console.log(localStorage.getItem("username")); // "Metehan"
// Delete
localStorage.removeItem("username");
Areas of use
// Save
localStorage.setItem("username", "Metehan");
// Even if you turn it on and off it remains the same.
console.log(localStorage.getItem("username")); // "Metehan"
// Delete
localStorage.removeItem("username");
Theme / Dark Mode Preference Language Selection Form / Remember User Information Shopping Cart