JavaScript: localStorage
A short, tested JavaScript example for localstorage. Copy it and adjust the names and paths for your project.
JavaScript
localStorage.setItem("theme", "dark");
const theme = localStorage.getItem("theme"); // null if missing
localStorage.removeItem("theme");
// objects must be serialized
localStorage.setItem("user", JSON.stringify({ id: 1 }));
const user = JSON.parse(localStorage.getItem("user") ?? "null");Find it in Zest
Search for “javascript localstorage” in Zest and this example appears above the results, with other matches to choose from. Searches stay private.