Reputation: 1509
I am reading a tutorial about closure and it describes Execution Context as follows:
When a JavaScript function is executed, a construct referred to as an Execution Context is created. The Execution Context is an abstract concept prescribed by the specification to track the execution progress of its associated code. As an application runs, an initial Global Execution Context is created. As each new function is created, new Execution Contexts are created which form an Execution Context stack.
When a JavaScript function is executed, a construct referred to as an Execution Context is created.
This sentence says that an Execution Context is created when a function is executed.
As each new function is created, new Execution Contexts are created which form an Execution Context stack.
This sentence says that an Execution Context is created when a new function is created.
My question is: which one is right?
Upvotes: 0
Views: 415
Reputation: 665574
The first one. Execution contexts are created when functions are executed. The "execution context stack" is also known as "call stack".
When functions are created, they store a reference to the scope of the active execution context (that created them) - this is what we call a closure scope. When they will be executed, their execution context will be created with a new scope that is linked to the stored one - forming a scope chain.
Upvotes: 4