what is window 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: local storage javascript

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

Example 3: what is Window local storage

The read-only localStorage property allows you to access a 
Storage object for the Document's origin; 
the stored data is saved across browser sessions. 
except for "private browsing" or "incognito" session 

Data stored in localStorage is specific to the protocol of the page. 
In particular, data stored by a script on a site accessed 
		with HTTP (e.g., http://example.com) 
is put in a different localStorage object 
  			from the same site accessed with HTTPS (e.g., https://example.com).

The keys and the values are always 
in the UTF-16 DOMString format, 
which uses two bytes per character. 
As with objects, integer keys are automatically converted to strings.