check if key exists in localstorage javascript code example
Example 1: check if localstorage key exists
if (localStorage.getItem("username") === null) {
//...
}
Example 2: check if localstorage key exists js
if("user" in localStorage){
alert('yes');
} else {
alert('no');
}