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

**URL:** <https://es.discourse.group/t/are-function-parameters-and-inner-function-declarations-in-lexicalenvironment-or-variableenvironment/334>\
**Category:** I have questions\
**Created:** [May 16, 2020, 5:47pm UTC](https://es.discourse.group/t/are-function-parameters-and-inner-function-declarations-in-lexicalenvironment-or-variableenvironment/334 "2020-05-16T17:47:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sake25](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@sake25](https://es.discourse.group/u/sake25)\
**Post date:** [May 16, 2020, 5:47pm UTC](https://es.discourse.group/t/are-function-parameters-and-inner-function-declarations-in-lexicalenvironment-or-variableenvironment/334/1 "2020-05-16T17:47:49Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![claudiameadows](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudiameadows/32/126_2.png) [@claudiameadows](https://es.discourse.group/u/claudiameadows)\
**Post date:** [May 17, 2020, 11:56am UTC](https://es.discourse.group/t/are-function-parameters-and-inner-function-declarations-in-lexicalenvironment-or-variableenvironment/334/2 "2020-05-17T11:56:25Z")

</div>

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 `function`s get added to the variable environment as part of the hoisting process.

---

<div class="post-metadata">

**Author:** ![bergus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/bergus/32/152_2.png) [@bergus](https://es.discourse.group/u/bergus)\
**Post date:** [May 17, 2020, 3:46pm UTC](https://es.discourse.group/t/are-function-parameters-and-inner-function-declarations-in-lexicalenvironment-or-variableenvironment/334/3 "2020-05-17T15:46:32Z")

</div>

> [@sake25](#):
>
> Do a, b and bar belong to LexicalEnvironment or VariableEnvironment ?

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](http://www.ecma-international.org/ecma-262/#sec-functiondeclarationinstantiation). 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.

---

<div class="post-metadata">

**Author:** ![claudiameadows](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudiameadows/32/126_2.png) [@claudiameadows](https://es.discourse.group/u/claudiameadows)\
**Post date:** [May 18, 2020, 4:36am UTC](https://es.discourse.group/t/are-function-parameters-and-inner-function-declarations-in-lexicalenvironment-or-variableenvironment/334/4 "2020-05-18T04:36:09Z")

</div>

I'll stand corrected then.
