While researching, I discovered some intriguing discrepancies between the documentation regarding a commonly asked question.
The TypeScript docs suggest that variables declared with var
will escape the containing function's scope, but according to MSDN, data declared with var
remains accessible within the function. This discrepancy may stem from how Typescript handles var compared to ECMAScript, so I am seeking feedback on Stack Overflow.
Block-scoping When a variable is declared using let, it uses what some call lexical-scoping or block-scoping. Unlike variables declared with var whose scopes leak out to their containing function, block-scoped variables are not visible outside of their nearest containing block or for-loop.
However, as stated in the MSDN docs
Variables declared by let have their scope in the block for which they are defined, as well as in any contained sub-blocks. In this way, let works very much like var. The main difference is that the scope of a var variable is the entire enclosing function: