Activation and Variable Object in JavaScript?

Benny Tjia picture Benny Tjia · Jun 14, 2011 · Viewed 7.5k times · Source

Is the term "activation object" just another name of "variable object" or is there actually any difference between them? I have been reading a few JavaScript articles about how variable scopes are formed in an execution context, and from my point of view it seems that in most of the articles they use these two terms interchangeably.

Answer

nrabinowitz picture nrabinowitz · Jun 14, 2011

Well, I just learned something :). From this article, it would appear that within the execution context of a function, the Activation Object is used as the Variable Object:

When an execution context is created a number of things happen in a defined order. First, in the execution context of a function, an "Activation" object is created. [...]

Then the process of "variable instantiation" takes place using an object that ECMA 262 refers to as the "Variable" object. However, the Activation object is used as the Variable object (note this, it is important: they are the same object). Named properties of the Variable object are created for each of the function's formal parameters, and if arguments to the function call correspond with those parameters the values of those arguments are assigned to the properties (otherwise the assigned value is undefined).

However, when you're in the global scope, there isn't an Activation Object, so the Global Object is used as the Variable Object instead:

The global execution context gets some slightly different handling as it does not have arguments so it does not need a defined Activation object to refer to them. [...] The global object is used as the Variable object, which is why globally declared functions become properties of the global object.

So it sounds like "Activation Object" and "Variable Object" are the same thing within a function context, but not within the global context.