Are function parameters and inner function declarations in LexicalEnvironment or VariableEnvironment ?

Hello everyone,
I know let-defined variables are in LexicalEnvironment of running excution context while var-defined variables are in VariableEnvironment of running excution context.
So how about Function Parameters and Inner Function Declarations ?

Example code:
function foo(a, b) {
function bar() {
return 3;
-> Do a, b and bar belong to LexicalEnvironment or VariableEnvironment ?

Just going off memory (also not TC39), but IIRC parameters get put in the lexical environment (for cases like (a = a) => ... and (a = b, b = 1) => ... - those need to throw on invocation), and inner functions get added to the variable environment as part of the hoisting process.

Yes - to both, because in fact in your example the LexicalEnvironment and the VariableEnvironment are the same environment.

You can find the details in the FunctionDeclarationInstantiation spec. In general, top-level function declarations go in the same environment as var declarations, and in exceptional cases there's an extra lexical scope for the parameters around the body.

1 Like

I'll stand corrected then.