How to check if localStorage item exists
Deyan Petrov
Posted on August 7, 2022
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
}
💖 💪 🙅 🚩
Deyan Petrov
Posted on August 7, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
webdev Understanding the Spread Operator in JavaScript: A Simple Guide for Beginners
October 15, 2024