local storage
snippet in javascript

local storage javascript

user8201

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';

local storage

user1807

function setItem(name, value) {
  localStorage.setItem(name, value);
}
function getItem(name) {
  localStorage.getItem(name);
}
function deletItem(name) {
  localStorage.removeItem(name);
}
function clearStorage() {
  localStorage.clear();
}

local storage javascript

user6833

localStorage.setItem('user_name', 'Rohit'); //store a key/value
var retrievedUsername = localStorage.getItem('user_name'); //retrieve the key

save to local storage

user5157

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

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

localStorage.removeItem('myCat');

// Clear all items
localStorage.clear();

localstorage js

user6125

// Set
localStorage.setItem('monChat', 'Tom');

// Get
localStorage.getItem('myCat');

// Remove
localStorage.removeItem('myCat');

local storage

user1203

As the answers here already talk about the coding aspect. I will talk about
the concept.
Local storage is basically an object stored in the specific browser you are 
using in that moment. And thus it is tied to that browser in that device. It's 
duration is infinite so it never expires

If you only want to store data that only lasts for that browser session(
starts when you open a window and ends when you close it) then the best choice
is sessionStorage