4 ms·
I guess the point is that: // line 1 { // line 2 let x = 5; // line 3 // line 4 } // line 5 What is the actual end langu
by Macha 11y ago
I guess the point is that:
// line 1
{
// line 2
let x = 5; // line 3
// line 4
}
// line 5
What is the actual end language user difference between saying the scope of x is lines 2-4 but magic (TDZ) makes it unavailable on line 2 vs. saying the scope is from line 3 to 4 with the TDZ being an implementation detail?
- calebegg 11y agoOne 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.