How to check whether a Storage item is set?

The getItem method in the WebStorage specification, explicitly returns null if the item does not exist:

… If the given key does not exist in the list associated with the object then this method must return null. …

So, you can:

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

See this related question:

Leave a Comment