We are going to discuss Web Storage and its types in this article step-by-step
Introduction
- Web Storage is used to store data in our browser.
- Web Storage API stores data at the client-side in the key-value format.
- Web Storage is also called DOM Storage which provides many protocols and methods to store data on the browser.
Key – Identifier of the data
Value – The value which is stored corresponding to the key.
Types of Web Storage
There are two types of Web Storage which we used most of the time
- Local Storage
- Session Storage
Local Storage
- Local Storage is used to store data on the client side.
- The data which is stored in the local storage has no expiration. It will not be deleted automatically unless the user is deleted manually or programmatically.
- Web Storage has 10 Mb of size in most of the browsers to store data which is greater than cookies because in the cookies we can store only 4 KB of data.
- While using Local Storage the value must be always in string type when we stored the number it automatically converts and is considered as a string.
How to Store Data in Local Storage
There are multiple methods that are present related to local storage like setItem() is one of the methods which is used to store data in the local storage and it has two parameters one is the name of the key and the second one is the value which is of string type.
Open your browser and press F12 and open the inspect window over there

As you can see in the above image first we use the setItem() method of local storage which is to set the Product as a key and the Laptop as a value inside the local storage and later on, we take the value of the Product using getItem() of local storage which take the key as a parameter and return the value which is present against the key.
If you want to look at the data that are present in the local storage for that open the inspect window and inside the Application Tab and Storage section you can see the local storage section as shown in the below image

As you can see there is one section inside the storage section under the application tab related to local storage and the key and value which is stored in the key-value format.
We can store only string objects in local storage, but if we want to store any object in the local storage then there is one method called JSON.Stringify() which takes an object and converts that into the JSON Format and then stores it inside the local storage.








Join the conversation! Your thoughts help the community grow.