3 ms·
One case where the distinction matters is this: function x() { console.log(a); } let a = 10; x(); If you thought 'a' was only in scope o
by calebegg 11y ago
One case where the distinction matters is this:
function x() {
console.log(a);
}
let a = 10;
x();
If you thought 'a' was only in scope on lines 4 and 5 of the above snippet, you might assume that this snippet would return an error, but it doesn't; it prints 10. That's why it's a temporal dead zone, not a lexical dead zone.
That being said, I agree this is a weirdly overemphasized aspect of ES6. The TDZ is not some weird mysterious boogeyman. It's the thing that makes sense in nearly all cases.