0Pricing
JavaScript Academy · Lesson

localStorage vs sessionStorage

Choose the right storage lifetime.

Two Stores, Same API

localStorage and sessionStorage share identical methods. The difference is lifetime: how long the data survives.

localStorage Persists

Data in localStorage stays until explicitly removed. It survives page reloads, tab closes, and browser restarts.

localStorage.setItem("theme", "dark");
// Still there days later, after closing the browser

All lessons in this course

  1. Storing and Reading Data
  2. localStorage vs sessionStorage
  3. Storing Objects with JSON
  4. Storage Events and Limits
← Back to JavaScript Academy