Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(function () {
var g, h;
function x() { f = ""; /* var-scoped f gets value "" */ }
function y() { g = f; /* g gets value of var-scoped f */ }
/* var-scoped f is undefined, let-scoped f is a function */
h = f; /* h gets value of let-scoped f, a function */
f = 1; /* let-scoped f gets value 1 */
function f() {} /* var-scoped f gets value of let-scoped f, a number */
return [typeof f /* number */, typeof g /* string */, typeof h /* function */];
Copy link

bakkot commented Dec 6, 2015

Shouldn't typeof f be 1? Evaluating the line function f(){} has effect "set the value of the var-scoped binding to the value of the block-scoped binding" per B.3.3, and when that line is hit, the value of the block-scoped binding is 1.

This is my understanding of the semantics.

Copy link

michaelficarra commented Dec 6, 2015

You are completely right. I made a mistake, then checked my answer against Chakra, who's supposed to have done this correctly, and got the same answer. I've updated the example to be clearer (and hopefully right this time!), based on your fork. ❤️ Thanks, Kevin.

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