SyntaxFix
Write A Post
Hire A Developer
Questions
Update:
if (localStorage.hasOwnProperty("username")) { // }
Another way, relevant when value is not expected to be empty string, null or any other falsy value:
if (localStorage["username"]) { // }