JavaScript Web/Browser Storage

The Web Storage is used for storing and retrieving data in the browser. There are two type of storage:

  1. localStorage: It is a type of web storage that allows you to store data on the client-side, even after the browser is closed. The data is stored and available even after a page refresh or a browser restart.
  2. sessionStorage: It is stored for a single session and is deleted when the browser is closed. The data is not stored and is not available after a page refresh or a browser restart.

Both localStorage and sessionStorage can be accessed using the localStorage and sessionStorage properties of the window object in JavaScript. The data is stored in key-value pairs and has a limit of approx 5-10 MB, based on the browser type.

code example;

Output:

value1

value2

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top