what to use local storage for code example

Example 1: local storage javascript

function createItem() {
	localStorage.setItem('nameOfItem', 'value'); 
} 
createItem() // Creates a item named 'nameOfItem' and stores a value of 'value'

function getValue() {
	return localStorage.getItem('nameOfItem');  
} // Gets the value of 'nameOfItem' and returns it
console.log(getValue()); //'value';

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;

// set an item
storage.setItem("highscore", 76);

// get an item
let highscore = storage.getItem("highscore");

// remove an item
storage.removeItem("highscore");

// clear entire storage (NOT recommended as it also removes information about cookies, ad storage an so on)
storage.clear();