what to use local storage for code example
Example 1: local storage javascript
function createItem() {
localStorage.setItem('nameOfItem', 'value');
}
createItem()
function getValue() {
return localStorage.getItem('nameOfItem');
}
console.log(getValue());
Example 2: javascript localstorage
localStorage.setItem("user_name", "Bob");
document.body.addEventListener("click", function(){
alert(localStorage.getItem("user_name"))
});
Example 3: local storage javascript
let storage = window.localStorage;
storage.setItem("highscore", 76);
let highscore = storage.getItem("highscore");
storage.removeItem("highscore");
storage.clear();