Skip to content

Instantly share code, notes, and snippets.

@hoangtranson
Created August 4, 2019 13:20
Show Gist options
  • Save hoangtranson/081a2e017dd335d47d71d306dd79d4a9 to your computer and use it in GitHub Desktop.
Save hoangtranson/081a2e017dd335d47d71d306dd79d4a9 to your computer and use it in GitHub Desktop.
test hoisting on browser
var hoisted = "foo" in this;
console.log(`'foo' name ${hoisted ? "is" : "is not"} hoisted. typeof foo is ${typeof foo}`);
if (false) {
function foo(){ return 1; }
}
// In Chrome:
// 'foo' name is hoisted. typeof foo is undefined
//
// In Firefox:
// 'foo' name is hoisted. typeof foo is undefined
//
// In Edge:
// 'foo' name is not hoisted. typeof foo is undefined
//
// In Safari:
// 'foo' name is hoisted. typeof foo is function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment