best practice for checking if a variable is defined and not null:
if (typeof sideBar !== 'undefined' && sideBar !== null)
edited realized you're not checking if something is undefined, you're checking that it's defined, so edited again to answer your request more accurately