Hi, I'm Jacob. Enjoying devFlipCards? Buy me a coffee

12. What's the difference between local storage and session storage?

sessionStorage i localStorage are data containers, provided to application by browser. It holds data in text format as a key/value pairs. It's size depends on browser.

They share same API:

  • setItem(key, value) - ustawia wartość value pod kluczem key
  • getItem(key) - zwraca wartość spod klucza key
  • removeItem(key) - usuwa wartość spod klucza key
  • clear() - czyści pamięć.

Differences:

Session Storage:

  • Cleared on closing tab/browser
  • About 5MB memory
  • Is not shared between browser's tabs, even if they are under same domain

Local Storage:

  • It's not cleared automatically - it has to be cleared manually in devtools, in browser's settings or from code
  • About 5-10MB memory
  • Browser's tab share it if they are under same domain
Struggling to find common date to meet with your friends? Try our new tool
commondate.xyz