JavaScript localStorage

ยท

1 min read

LocalStorage is a data storage type of web storage. This allows the JavaScript sites and apps to store and access the data without any expiration date. This means that the data will always be persisted and will not expire. So, data stored in the browser will be available even after closing the browser window.

In short, all we can say is that the localStorage holds the data with no expiry date, which is available to the user even after closing the browser window. It is useful in various ways, such as remembering the shopping cart data or user login on any website.

localStorage Methods

#Save Data to Local Storage -> localStorage.setItem(key, value);

#Read Data from Local Storage -> let lastname = localStorage.getItem(key);

#Remove Data from Local Storage -> localStorage.removeItem(key);

#Remove All (Clear Local Storage) ->localStorage.clear();

ย