javascript localstorage check if item exists code example
Example 1: javascript check if variable exists
if (typeof myVar !== 'undefined') {
// myVar is defined
}
Example 2: check if localstorage key exists
if (localStorage.getItem("username") === null) {
//...
}
Example 3: check if localstorage key exists js
if("user" in localStorage){
alert('yes');
} else {
alert('no');
}