Let's make this short. Since localStorage.getItem("item")
returns a null
if it is missing, we simply need to check if the return value is not null
if (localStorage.getItem("item") !== null) {
console.log("Item exists")
//Do stuff
} else {
console.log("Item does not exist")
//Do other stuff
}
Top comments (0)