1

I've already read :

What is the difference and relationship between execution context and lexical environment?

Lexical environment and function scope

https://262.ecma-international.org/6.0/#sec-lexical-environments

https://262.ecma-international.org/6.0/#sec-execution-contexts and more...

Just want to clarify one final time for myself. What is the actual difference between Lexical Environment vs Execution Context?

Am I right that they're absolutely the same thing, but Execution Context is actually one of Lexical Environments in our code that is currently on the top of our callstack??

So let's say we have

1 function one() {
2  return
3 }
4
5 function two() {
6  one()
7 }
8
9 two()

First we have out global context in the stack, it's currently our Execution Context. Browser starts running our code, goes down to line 9 and put function two() on the top of the call stack. So now our Execution Context is the Lexical Environment of this function. Is that correct or am I missing smth? Thanks for help!

Roman2021
  • 19
  • 4
  • Unless you have closures, there's little significant difference. – Barmar Aug 26 '22 at 22:52
  • 3
    The Lexical Environment is a component of the Execution Context. But it certainly isn't the whole thing. Nowhere in the Lexical Environment is the information about where the function should return to, for example, or the chain of execution contexts through which exceptions should be thrown. – rici Aug 27 '22 at 00:57
  • "*Am I right that they're absolutely the same thing*" - no. Not at all. – Bergi Aug 27 '22 at 00:58
  • "*Execution Context is actually one of Lexical Environments*" - no, an execution context is not a lexical environment. – Bergi Aug 27 '22 at 00:58
  • 2
    I don't see how this question is different from, or expects to get different answers than, the other questions you already found. (Thanks for sharing your research and linking them, though!) What exactly do the answers there leave unclear? – Bergi Aug 27 '22 at 01:01

0 Answers0