const isPresent = foo !== undefined; // ReferenceError: foo is not defined
const isPresent = window.foo !== undefined;
This implementation works as the initial variable that we are dereferencing (
window) exists, and instead the check is now preformed on the windows value (an object) instead.
undefined when trying to access a non-existent property.
This check however, can seem a little limited in scope, so instead the more generic (and recommended) way for checking if a variable has been defined or not is as follows.
const isPresent = typeof foo !== 'undefined';