Archives For fundamentals

In JavaScript, the term ‘Variable object’ is a general or abstract term used to refer to the object that holds the properties that describe the environment and scope of the currently executing context. Simply put, it’s the object that holds variables declared against the executing context (i.e., variables declared with the var keyword). Note that it’s just an ABSTRACT concept. Hence, what the Variable object actually is at a given point of execution is dependent on the scope of the currently executing context. When in the global scope (i.e., outside of any functions), the GLOBAL object becomes the variable object. Why? Because it’s the object that holds the properties that describe the environment and scope of the global executing context. In the browser, because the global or outermost executing environment is the browser WINDOW, it is the window object that ends up being used as the Variable object, due to it being the object that describes the global executing environment. This is why variables declared with the var keyword outside of functions end up on the window object (i.e., foo="foo" ends up being accessible as window.foo).

Now when in the function local scope (i.e., when inside of a function), an object called an ‘Activation’ object becomes the variable object. Why? Because it is the object that holds the properties that describe the environment and scope of the currently executing function. It is on this object that function arguments for example, are held. As an aside, by definition, to ACTIVATE something is to cause that thing to act or FUNCTION. As such, when you hear the term ‘Activation object’, think ‘FUNCTION’ object, or better yet, the root object that is LOCAL to a function (i.e., the FUNCTION LOCAL OBJECT).

With regards to the relationship between the Variable, Global and Activation object, think in terms of abstract inheritance (i.e., inheriting from an abstract type), where the Variable object is the ABSTRACT type, and the Global and Activation objects are CONCRETE instances of that abstract type.

 

Depicts the abstract relationship between the variable object and the global and activation object.

 

In this way, the Global and Activation objects can be said to be TYPES of Variable objects. By itself the term ‘variable object’ is just a general term used to describe any object that is used to store the variables that are declared with the var keyword within a given execution context. It’s similar to how the abstract term ‘HUMAN’ is used to generally describe a MAN or a WOMAN.