Ecma262: About "LexicalEnvironment" and "VariableEnvironment"

Created on 19 Nov 2016  Â·  1Comment  Â·  Source: tc39/ecma262

Sorry to bother you for my confusion. I post a question What's the difference between “LexicalEnvironment” and “VariableEnvironment” in spec on stackoverflow.

I find that there is some people have the same confusion, such as Clarity on the difference between “LexicalEnvironment” and “VariableEnvironment” in ECMAScript/JavaScript, Why do catch clauses have their own lexical environment?

I read some answers, some of them clarify me, but I still have some confusion.

So I hope that you can answer the question to help me to understand it.

@wycats @bterlson @rwaldron @caridy @allenwb Thanks.

question

Most helpful comment

A LexicalEnvironment is a local lexical scope, e.g., for let-defined variables. If you define a variable with let in a catch block, it is only visible within the catch block, and to implement that in the spec, we use a LexicalEnvironment. VariableEnvironment is the scope for things like var-defined variables. vars can be thought of as "hoisting" to the top of the function. To implement this in the spec, we give functions a new VariableEnvironment, but say that blocks inherit the enclosing VariableEnvironment.

Hope this helps. (Could someone with the rights please close this bug?)

>All comments

A LexicalEnvironment is a local lexical scope, e.g., for let-defined variables. If you define a variable with let in a catch block, it is only visible within the catch block, and to implement that in the spec, we use a LexicalEnvironment. VariableEnvironment is the scope for things like var-defined variables. vars can be thought of as "hoisting" to the top of the function. To implement this in the spec, we give functions a new VariableEnvironment, but say that blocks inherit the enclosing VariableEnvironment.

Hope this helps. (Could someone with the rights please close this bug?)

Was this page helpful?
0 / 5 - 0 ratings