<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<p id="demo" style="font-weight:bold;"></p>
localStorage.setItem("username",'My name is XYZ'); document.getElementById("demo").innerHTML = localStorage.getItem("username");
- localStorage.setItem() is used to set the value in a local storage variable.
- localStorage.getItem() is used to get the value of the variable stored on the local storage.
If you notice the above example then you know that I have set the value “My name is XYZ” in the first parameter of the setItem() method. On the other hand, I have used this parameter in the getItem() method to get the value of that variable.
Conclusion:- I hope this tutorial will help you to understand the overview. If there is any doubt then please leave a comment below.
Originally published at https://pbphpsolutions.com on June 25, 2022.