Last active
April 4, 2018 21:20
-
-
Save rwaldron/f0807a758aa03bcdd58a to your computer and use it in GitHub Desktop.
Temporal Dead Zone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// The block has begun, we're in a new block scope. The TDZ for the "a" binding has begun | |
var f = function() { | |
// 2. Because f() is evaluated before `a` is actually declared, | |
// an exception will be thrown indicating to the author that | |
// `a` is not yet defined. | |
console.log(a); | |
}; | |
f(); // 1. f is called and results evaluated before the next line... | |
let a = 1; | |
// The `a` binding is now safe, but we never got here because f() killed us :( | |
// that's ok, because we can fix this bug and celebrate the win! | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// The block has begun, we're in a new block scope. The TDZ for the "a" binding has begun | |
// Declare `a` before use. | |
let a = 1; | |
var f = function() { | |
// 2. Because f() is evaluated after `a` is declared, | |
// the value of `a` will be logged. | |
console.log(a); | |
}; | |
f(); // 1. f is called and results evaluated | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's what I would also show: