New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About "LexicalEnvironment" and "VariableEnvironment" #736

Closed
NE-SmallTown opened this Issue Nov 19, 2016 · 1 comment

Comments

Projects
None yet
4 participants
@NE-SmallTown

NE-SmallTown commented Nov 19, 2016

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.

@littledan

This comment has been minimized.

Show comment
Hide comment
@littledan

littledan Nov 19, 2016

Member

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?)

Member

littledan commented Nov 19, 2016

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?)

@domenic domenic closed this Nov 19, 2016

@bterlson bterlson added the question label Nov 21, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment