0

I am trying to see if a KEY is stored in the users localStorage, but I every code I seem to try either says its always found regardless of whether its there or not.

JS

if (localStorage.getItem(2) === null) {
  alert('not found');
} else {
    alert('Found!');
}

The key is the number 2, I have tried wrapping the number in double quotes but regardless of whether the key is there or not it always says its found.

InvalidSyntax
  • 9,131
  • 20
  • 80
  • 127

0 Answers0