What is web storage in javascript with example?

Priti Jha
2 min readFeb 10, 2023

--

Web storage in JavaScript is a way to store data on the client-side, allowing you to persist data across multiple sessions and pages. There are two types of web storage in JavaScript: local storage and session storage.

Local Storage: Local storage is a type of web storage that allows you to store data even after the user closes the browser or the computer is restarted. Data stored in local storage remains available even if the user revisits the website after several days.

Here’s an example of using local storage in JavaScript:

Session Storage: Session storage is a type of web storage that allows you to store data for a single session. Data stored in session storage is available only for the duration of the current session, and is deleted when the user closes the browser.

Here’s an example of using session storage in JavaScript:

In both local storage and session storage, the setItem method is used to store data, the getItem method is used to retrieve data, and the removeItem method is used to remove data. The data stored in web storage is key-value pairs, where the key is a string and the value can be any JavaScript data type, such as a string, number, or object.

--

--

Priti Jha
Priti Jha

Written by Priti Jha

Senior front-end developer writing about Angular 8 , Ionic Framework ,Javascript, HTML, Css and all front end technology.

No responses yet