How can I check if an item is set in localStorage? Currently I am using
if (!(localStorage.getItem("infiniteScrollEnabled") == true || localStorage.getItem("infiniteScrollEnabled") == false)) {
// init variable/set default variable for item
localStorage.setItem("infiniteScrollEnabled", true);
}
The
getItemmethod in the WebStorage specification, explicitly returnsnullif the item does not exist:So, you can:
See this related question: