how to check if local storage variable exists in javascript

JavaScript
if (localStorage.getItem("username") === null) {
  //...
}
Source

Also in JavaScript: