localStorage vs sessionStorage
Understand the lifetime and scope of each storage type.
Web Storage API Overview
The Web Storage API provides two client-side key-value stores: localStorage (persistent across sessions) and sessionStorage (cleared when the tab closes). Both store string values and are accessible synchronously via JavaScript on the same origin.
localStorage Persistence
Data in localStorage persists until explicitly cleared by code, the user, or browser data deletion. It survives browser restarts, page refreshes, and tab closes. Capacity is typically 5-10MB per origin depending on browser.
All lessons in this course
- localStorage vs sessionStorage
- Getting Setting and Removing Items
- Listening for Storage Events
- Security What Never to Store in Storage