SyntaxFix
Write A Post
Hire A Developer
Questions
You can also try this if you want to check for undefined:
if (localStorage.user === undefined) { localStorage.user = "username"; }
getItem is a method which returns null if value is not found.