Skip to content

Instantly share code, notes, and snippets.

@bakkot
Forked from michaelficarra/es6-fd-block-scoping.js
Last active December 6, 2015 21:26
Show Gist options
  • Save bakkot/1a0ad520485265b1ef87 to your computer and use it in GitHub Desktop.
Save bakkot/1a0ad520485265b1ef87 to your computer and use it in GitHub Desktop.
(function () {
var g, h;
function x() { f = ""; }
function y() { h = f; }
{
// var-scoped f is undefined, let-scoped f is a function
f = 1; // let-scoped f gets value 1
x(); // var-scoped f gets value ""
y(); // h gets value of var-scoped f
function f() {} // var-scoped f gets value of let-scoped f
g = f; // g gets value of let-scoped f
}
return [typeof f /* number */, typeof g /* number */, typeof h /* string */];
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment