Skip to content

Instantly share code, notes, and snippets.

@timruffles
Created January 5, 2017 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timruffles/4217725e9a9cae931078f13ec8d9101d to your computer and use it in GitHub Desktop.
Save timruffles/4217725e9a9cae931078f13ec8d9101d to your computer and use it in GitHub Desktop.
hoistage
// Difference between lintability/RTE of hoisting vs non-hoisted code
// ReferenceError: foo is not defined
// at <anonymous>:3:5
try {
foo()
const x = 1;
const foo = () => x;
} catch(e) {
console.log(e)
}
// Hoisted version - you get a longer stack.
// Statically analysable (lintable): foo2 depends statically on const x, and foo2() is called before const x
// is in scope.
// ReferenceError: x is not defined
// at foo2 (<anonymous>:14:23)
// at <anonymous>:12:5
try {
foo2()
const x = 1;
function foo2() { x };
} catch(e) {
console.log(e)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment