Categories
JavaScript Answers

How to check whether a Storage item is set with JavaScript?

Spread the love

To check whether a Storage item is set with JavaScript, we use the getItem method.

For instance, we write

if (localStorage.getItem("infiniteScrollEnabled") === null) {
  //...
}

to check if the local storage item with key 'infiniteScrollEnabled' with the getItem method.

If it’s null, then the item with key 'infiniteScrollEnabled' doesn’t exist in local storage.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *