I have this code:
var sideBar = localStorage.getItem(\'Sidebar\');
I want to check if sideBar is defined and not null in an if statement. I am
As W3 Manual explicitly explained: The getItem(key) method must return the current value associated with the given key. If the given key does not exist in the list associated with the object then this method must return null.
It means, no need to check undefined, If it is undefined then the result of the getItem() method will be null. You need to just check against null.
if (localStorage.getItem("Sidebar") !== null) {
//...
}