引用于ECMAScript 2015规范—表23
LexicalEnvironment: Identifies the Lexical Environment used to resolve identifier references made by code within this execution context.
VariableEnvironment: Identifies the Lexical Environment whose EnvironmentRecord holds bindings created by VariableStatements within this execution context.
The LexicalEnvironment and VariableEnvironment components of an execution context are always Lexical Environments. When an execution context is created its LexicalEnvironment and VariableEnvironment components initially have the same value.
LexicalEnvironment:标识用于解析代码在此执行上下文中进行的标识符引用的词汇环境。
VariableEnvironment:标识其EnvironmentRecord保存在此执行上下文中由VariableStatements创建的绑定的词汇环境。
执行上下文的LexicalEnvironment和VariableEnvironment组件始终是词汇环境。创建执行上下文时,其LexicalEnvironment和VariableEnvironment组件最初具有相同的值。
来自于ECMA262组织littledan的解答
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.
LexicalEnvironment是一个局部词法范围,例如,用于let定义的变量。如果在catch块中定义一个带有let的变量,那么它只在catch块中可见,为了在规范中实现它,我们使用了LexicalEnvironment。VariableEnvironment是var定义变量之类的范围。VAR可以被认为是“提升”到函数顶部。为了在规范中实现这一点,我们给函数一个新的VariableEnvironment,但是说块继承了封闭的VariableEnvironment。
参考ECMA官方解释
词法环境是一种规范类型,基于 ECMAScript 代码的词法嵌套结构来定义标识符和具体变量和函数的关联。一个词法环境由环境记录器和一个可能的引用外部词法环境的空值组成。
执行上下文的LexicalEnvironment和VariableEnvironment组件始终是词法环境。创建执行上下文时,它的LexicalEnvironment和VariableEnvironment组件最初具有相同的值。
在 ES6 中,词法环境组件和 变量环境组件的一个不同就是前者被用来存储函数声明和变量(let 和 const)绑定,而后者只用来存储 var 变量绑定。
个人理解
变量环境是一个相对环境,它是在当前作用域向上可以去获取到其他定义的变量的多层级环境。
词法环境是一个内部环境,它的内部结构化了词法环境+变量环境。