Javascript - Function Execution Context

Introduction

The execution context of a variable or function defines what other data it has access to and how it should behave.

Each execution context has an associated variable object on which all of its defined variables and functions exist.

The global execution context is the outermost one.

Depending on the host environment for an ECMAScript implementation, the object representing this context may differ.

In web browsers, the global context is that of the window object, so all global variables and functions are created as properties and methods on the window object.

When an execution context has executed all of its code, it is destroyed, along with all of the variables and functions defined within it.

The global context isn't destroyed until the application exits, such as when a web page is closed or a web browser is shut down.

Each function call has its own execution context.

Whenever code execution flows into a function, the function's context is pushed onto a context stack.

After the function has finished executing, the stack is popped, returning control to the previously executing context.