DEV Community

Cover image for LOCAL STORAGE
Madhusudhan
Madhusudhan

Posted on

LOCAL STORAGE

Hi Every one this time I want share you about local storage. this quite impressing toipce let us Start.

Local Storage
local storage is a property of the window object that can store data in the user's computer. with this computer will remember information to use everytime use visite the website.

What we could store : name, note, messsage, preferences and etc.

What we could not store :password, confidential information becouse localstorage is not a safe places save it.

the data mush store in the from of string it is mostly used in the Todo list. impress the users while using the website.

localStorage.user = {name: "John"};
alert(localStorage.user);
Enter fullscreen mode Exit fullscreen mode

we can also remove the data from local storage.

localStorage.removeItem("mytime");
Enter fullscreen mode Exit fullscreen mode

Session Storage
Session storage is very similar to localstorage. there is only different that the data is only kept during the session. This means that if the user closes the tab or the browser the information is erased.

session storge is mostily used in the setitem and removeitem methods to store and erase data.

// Save data to sessionStorage
sessionStorage.setItem("key", "value");

// Get saved data from sessionStorage
let data = sessionStorage.getItem("key");

// Remove saved data from sessionStorage
sessionStorage.removeItem("key");

// Remove all saved data from sessionStorage
sessionStorage.clear();
Enter fullscreen mode Exit fullscreen mode

This is the related video

Thank You for Reading any question can ask me in comment.

Top comments (0)