Skip to content

Instantly share code, notes, and snippets.

@bakkot
Created November 29, 2016 21:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bakkot/60121065ef615c26f8bdf42839e310df to your computer and use it in GitHub Desktop.
Save bakkot/60121065ef615c26f8bdf42839e310df to your computer and use it in GitHub Desktop.
var p = () => console.log(f);
{
p(); // undefined
console.log(f); // function f(){}
f = 1;
p(); // undefined
console.log(f); // 1
function f(){}
p(); // 1
console.log(f); // 1
f = 2;
p(); // 1
console.log(f); // 2
}
@bakkot
Copy link
Author

bakkot commented Dec 15, 2016

I should mention that this is just a compatibility hack in the specification, since block-scoped function declarations were not previously a part of the ECMAScript spec but were commonly supported with inconsistent semantics in browsers. These semantics are only intended to capture behavior which would have worked across browsers, to avoid breaking things which previously worked everywhere; it's not intended to be sensible.

Don't write sloppy-mode code and you won't need to worry about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment