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
devFlipCards 2024

Do you accept cookies?

Cookies are small amounts of data saved locally on you device, which helps our website - it saves your settings like theme or language. It helps in adjusting ads and in traffic analysis. By using this site, you consent cookies usage.