1function createItem() {
2 localStorage.setItem('nameOfItem', 'value');
3}
4createItem() // Creates a item named 'nameOfItem' and stores a value of 'value'
5
6function getValue() {
7 return localStorage.getItem('nameOfItem');
8} // Gets the value of 'nameOfItem' and returns it
9console.log(getValue()); //'value';
1localStorage.setItem('user_name', 'Rohit'); //store a key/value
2var retrievedUsername = localStorage.getItem('user_name'); //retrieve the key
1The read-only localStorage property allows you to access a
2Storage object for the Document's origin;
3the stored data is saved across browser sessions.
4except for "private browsing" or "incognito" session
5
6Data stored in localStorage is specific to the protocol of the page.
7In particular, data stored by a script on a site accessed
8 with HTTP (e.g., http://example.com)
9is put in a different localStorage object
10 from the same site accessed with HTTPS (e.g., https://example.com).
11
12The keys and the values are always
13in the UTF-16 DOMString format,
14which uses two bytes per character.
15As with objects, integer keys are automatically converted to strings.
16