LocalStorage vs. SessionStorage

Permanent localStorage

It is kind of permanent storage as it withstands the opening and closing of browser window.

sessionStorage is session based.

It is lost as soon as the browser window is closed.

Page refreshes.

sessionStorage and localStorage both survive page refreshes.

sessionStorage is not session cookie.

sessionStorage is for the current tab only. As soon as a new tab is opened, even though same session cookie is used, a new sessionStorage is provided.


Note: Let's stop and think what it means for a while. Session cookies are available across browser tabs, that's why:

  • you can access only one account on most online applications.
  • you stay logged in on newer tab you opened. That's how you can see a thing on amazon up close and add to your current cart.
  • this however creates a security risk vector. A loophole in browser's implementation can hand your session cookies to almost everyone.

No expiration for localStorage

Technically, localStorage items can survive in browsers almost forever.