You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it intentional that the following fails to compile?
letx=5;{console.log(x);// Block-scoped variable 'x' used before its declarationletx=x;// Block-scoped variable 'x' used before its declarationconsole.log(x);}
The inner x is effectively shadowing the outer x, but only at and after the point it is redefined (i.e. the inner let x)
I couldn't find any specific mention of this in #904 which appears to be the documentation for let right now (via the spec)
Thanks
The text was updated successfully, but these errors were encountered:
It's actually part of the ECMAScript standard. Every block introduces its own environment record and creates a local binding for each lexical declaration (i.e. each let, const, etc.). That means that even if you shadow an outer variable later in your block, any prior uses in the block will still refer to the one declared later in the same block.
In an ES2015+ runtime, that would cause a ReferenceError to get thrown. In TypeScript, we give you a compile-time error.
Tested with
1.8
and1.9.0-dev.20160406
Is it intentional that the following fails to compile?
The inner
x
is effectively shadowing the outerx
, but only at and after the point it is redefined (i.e. the innerlet x
)I couldn't find any specific mention of this in #904 which appears to be the documentation for
let
right now (via the spec)Thanks
The text was updated successfully, but these errors were encountered: