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.
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?)
Most helpful comment
A LexicalEnvironment is a local lexical scope, e.g., for
let-defined variables. If you define a variable withletin 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 likevar-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?)