Check if Item Exists in localStorage

Checks if a specific item exists in localStorage.

Contributed by @ditinagrawal

javascript
function isItemInLocalStorage(key) {
  return localStorage.getItem(key) !== null;
}
javascript
isItemInLocalStorage("user"); // Output: true or false
GitHubEdit on GitHub