Skip to main content

Difference between Local Storage and Session Storage in JavaScript

This article will let us know about the difference between local storage and session storage and why it is a very relevant topic to know about.

Criteria Local Storage Session Storage
Read Property: Local storage is a read-only property that provides access to the document's local storage object, and the stored data is stacked up across browser sessions.
 
Session storage can be accessed using the session storage read-only property.
 
Page Expirations: Local storage data is not expired.
 
Session storage data is often cleared as soon as the page session ends.
 
Session Duration: Local storage lasts until it is deleted or the user deletes it.
 
Session storage is accessible only when the window created is still open and lasts until the user deletes it.
 
Usage: Local storage is used for long-term use.
 
Session storage is used when we need to store something that changes are temporary.
 
Storage: Local storage maintains a separate storage area for each given origin that is available for the duration of the page session but remains open even when the browser is closed and reopened.
 
Session storage does the same thing, but it only happens if the browser is still open, including page reloads and restores.
 
Page Expiration: Local storage stores data with no such expiration date and is only cleared through javascript or locally stored data.
 
Session storage stores data only for the session, which will be available until the browser or tab is closed.
 
Storage Limit: Local storage's storage limit is the maximum of the two.
 
The session storage limit is more significant than a cookie, almost 5MB.
Tags
Submitted by arilio666 on May 4, 2022

Ashwin is working with iVagus as a Technical Lead. He has experience in various technologies like Cypress, JavaScript, TypeScript, Rest Assured, Selenium, Cucumber, and Java.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.