0

I try to understand how closure is working under the hood. So I've read a lot of documentation and so many different websites.

Then I read this Variable Environment vs lexical environment

And in old documentation (2011) https://262.ecma-international.org/5.1/#sec-10.2

there are two different things, LE and ER.

But in modern https://262.ecma-international.org/12.0/#sec-environment-records

There is only one, environment record, and description of it is very similar to the old describe of lexical environments/

So, I am really confusing. Does LE still exist for modern javaScript (ecmaScript 6+)? What the difference between LE and ER?

knotri
  • 193
  • 1
  • 15
  • 2
    It looks like LE and ER were just folded into a single type. The spec seems to say that a LE has a reference to an outer LE, and now the ER itself has such a reference. However, that difference isn't really relevant to know/learn how closures work: (1) Environments are nested and a "child" environment has a reference to its "parent" environment. If a variable isn't found in a child, it's looked for in the parent, etc. (2) A function has a reference to the environment it was created in. Variables not declared inside the function are looked up there. – Felix Kling Sep 22 '21 at 17:06
  • 2
    Note that this is all just specification terminology. Nothing *changed* (other than new features being added). it's just the terms that the specification used to describe behavior were tweaked a bit. Closures still work like they always have. – T.J. Crowder Sep 22 '21 at 17:58

0 Answers0