check localstorage if exists 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');
}