dom local storage 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: js local storage

myStorage = localStorage;

localStorage.setItem('myCat', 'Tom');

var cat = localStorage.getItem('myCat');

localStorage.removeItem('myCat');

localStorage.clear();

Example 3: localstorage javascript

// Store
localStorage.setItem("lastname", "Smith");
// Retrieve

document.getElementById("result").innerHTML = localStorage.getItem("lastname");