Web Storage provides two APIs for storing data in the browser without sending it to the server on every request — a massive improvement over the original cookies. localStorage localStorage is persistent: data stays even after the browser closes. It is scoped to the origin (protocol + domain + port). Max storage is typically 5–10 MB depending on the browser. Great for user preferences, theme settings, or cached data. sessionStorage sessionStorage is session-scoped: data is cleared when the browser tab is closed. Each tab gets its own sessionStorage. Great for one-time form data, temporary authentication state, or wizard step data. API Interface Both APIs have the same interface: setItem(key, value), getItem(key) → string null, removeItem(key), clear(), and a length property. Important…
Key Takeaways
localStorage persists; sessionStorage clears on tab close.
Both store STRINGS only — use JSON.stringify/parse for objects.
Max 5–10 MB; synchronous; accessible by all scripts on origin.
Never store sensitive data (passwords, tokens) in Web Storage.
Use IndexedDB for large structured data; Cache API for offline.