The execution context of a variable or function defines what other data it has access to, as well as how it should behave. Each execution context has an associated variable object upon which all of its defined variables and functions exist. This object is not accessible by code but is used behind the scenes to handle data.
The global execution context is the outermost one.In web browsers, the global context is 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, taking with it 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).
When code is executed in a context, a scope chain of variable objects is created. The purpose of the scope chain is to provide ordered access to all variables and functions that an execution context has access to. The front of the scope chain is always the variable object of the context whose code is executing.If the context is a function, then the activation object is used as the variable object. An activation object starts with a single defined variable called arguments. The next variable object in the chain is from the containing context, and the next after that is from the next containing context. This pattern continues until the global context is reached; the global context's variable object is always the last of the scope chain.
No Block-Level Scopes
In languages such as C, C++, and Java, the variable defined in flow-control statements would be destroyed after the statement is executed, but except in javascipt.
When a variable is declared using var, it is automatically added to the most immediate context available. In a function, the most immediate one is the function's local context. If a variable is initialized without first being declared, itgets added to the global context automatically.It's advisable to always declare variables before initializing them.