localStorage.setItem("name", "Data");
localStorage.getItem("name"); // "Data"

Web storage API to store and retrieve data in browsers, localStorage stores data even when browser is closed, has no expiraion date.

function populateStorage() {
  localStorage.setItem("1", "1");
  localStorage.setItem("2", "2");
  localStorage.setItem("3", "3");

  return localStorage.length; // Should return 3
}

Returns the number of items stored in storage object.

sessionStorage.setItem("name", "Temporary Data")
sessionStorage.getItem("name"); // "Temporary Data"

Data is cleared when the page session ends.

localStorage.setItem("item", "dataToBeRemoved");
localStorage.removeItem("item"); 

To remove an item from storage.

localStorage.key(index); 

Returns the name of a storage object by index.

localStorage.clear();

Clears all keys from a given storage.