0

In ECMASCript spec said that after function invocation we have a new creation of a specified execution context for an appropriate function. So, consider the following simple function:

function(){
    var a='a';
    return 0;
}

After function invocation we have that a new execution context will be created. But after return statement is executed we have returned to an execution context from which our function is called. But what about function's execution context? Is there exist even after we're leaving from this?

2 Answers 2

3

When the function returns, assuming there are no closure references outstanding, the execution context is destroyed. It's up to the specific implementation to determine when to actually free up the memory.

Sign up to request clarification or add additional context in comments.

2 Comments

Is it true that if we call a function several times we just entering to a one execution context? Execution context doesn't re-creating.
No. That is not true. Each time you call the function in your example, a separate local variable a is created.
0

In javascript we have:

  • Global code/context – The default envionment where your code is executed for the first time.
  • Function code/context – Whenever the flow of execution enters a function body.
  • Eval code/context – Text to be executed inside the internal eval function.

You can have any number of function contexts, and each function call creates a new context, which creates a private scope where anything declared inside of the function can not be directly accessed from outside the current function scope.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.