Local Storage vs Session Storage IN Javascript 



Local Storage


In local storage, the data is stored in the local
Memory of web browser and local Storage data don't have any expiry date and the data is stored in key-value pairs

Local Storage Methods()


1.setItem();
2.getItem();
3.removeItem();
4.clear();


How to use it?


Window.localStorage;
//it is used to get the window local storage length 


Local Storage Methods 


1.setItem();
It is used to set items in the local storage of the web browser
Example:
localStorage.setItem(name,'Tech Search');

2.getItem();
Used to get the item from Local Storage
Example:
Let name=localStorage.getItem(name);
Console.log(name);

3.removeItem();
Used to remove specific elements from local storage 
Example:
localStorage.removeItem(name);

4.clear();
It's used to clear the local storage 
Example:
localStorage.clear();

Session Storage 


In session storage, the data is stored for a particular session. And the data will be lost when the web browser is closed.


Session Storage Methods()


1.setItem();
2.getItem();
3.removeItem();
4.clear();


How to use it?


Window.sessionStorage;
//it is used to get the window local storage length 

Session Storage Methods 


1.setItem();
It is used to set items in the session storage of the web browser
Example:
sessionStorage.setItem(name,'Tech Search');

2.getItem();
Used to get the item from session Storage
Example:
Let name= sessionStorage.getItem(name);
Console.log(name);

3.removeItem();
Used to remove specific elements from session storage 
Example:
sessionStorage.removeItem(name);

4.clear();
It's used to clear the session storage 
Example:
sessionStorage.clear();

RECAP

Local Storage and Session Storage 


Local storage is used to store the data in the storage of a web browser and the data don't have any expiry date, in session storage, the data is stored for a particular sessions


Methods


Local & Session Storage have the same methods to perform different activities and these most used methods are

1.setItem();
2.getItem();
3.removeItem();
4.clear();