# Check if a key exists in local storage using JavaScript

By Atta Ur Rehman Shah (https://attacomsian.com/about). Published Dec 3, 2020. Topics: JavaScript.
Canonical URL: https://attacomsian.com/blog/javascript-local-storage-check-key-exists

> A quick guide to learn how to check if an item is set in local storage or not using JavaScript.

To check if a key exists in HTML [local storage](https://attacomsian.com/blog/web-storage-api-local-storage-session-storage#removing-data) by using JavaScript, you can use the `getItem()` method of the `localStorage` object.

The `getItem()` method returns the current value associated with the given key. If the key does not exist, `getItem()` returns `null` which is sufficient to verify if the key exists or not:

```javascript
if (localStorage.getItem('email') !== null) {
    console.log(`Email address exists`);
} else {
    console.log(`Email address not found`);
}
```

Take a look at [this article](https://attacomsian.com/blog/web-storage-api-local-storage-session-storage) to learn more about HTML web storage API and how to use `localStorage` and `sessionStorage` objects to store data in the user's browser.
