4 min read
Browser Storage
localStorage lets a web page store small amounts of data in the
browser, which persists even after the page is closed and reopened.
localStorage.setItem("username", "Ada");
console.log(localStorage.getItem("username"));
localStorage.removeItem("username");
Common mistakes
localStorageonly stores strings — storing an object requiresJSON.stringify()first, andJSON.parse()when reading it back.- Never store sensitive data (passwords, tokens) in
localStorage— any script running on the page (including from an XSS attack) can read it.