How to use localStorage

JavaScript Oct 18, 2022

localStorage is a property that allows JavaScript sites and apps to save key-value pairs in a web browser with no expiration date. This means the data stored in the browser will persist even after the browser window is closed.

Here are the key methods of using localStorage:

  • setItem()
  • getItem()
  • removeItem()
  • clear()
  • key()

Here is how to use it:

window.localStorage.setItem('name', 'Elon Musk');

And that's all!

Tags