javascriptcallstackexecutioncontextjavascript-engine

Why are function expressions not included in the variable object of the Execution Context?


While going through the Execution Context part of the JavaScript.The Core. (1st ed.) by Dmitry Soshnikov, I came across this line that explicitly says that function expressions are not included in the variable object property of an execution context.

A variable object is a container of data associated with the execution context. It’s a special object that stores variables and function declarations defined in the context.

Notice, that function expressions (in contrast with function declarations) are not included in the variable object.

I understand that representation of an execution context as objects is an abstract concept and specifics may differ from one case to another, but still, I am interested to know why the author explicitly says that functions expressions are not to be included.

AFAIK, function expressions are treated as any other variables by JavaScript engines, and I don't see a reason why they should be omitted from variable objects.

Edit1: As per Quentin's answer, my conception about function expressions being treated as ordinary variables by JS engines(as stated in the para above) was wrong. But still, the question stands.


Solution

  • I am interested to know why the author explicitly says that functions expressions are not to be included.

    We don't know, you'd have to ask the author :-)

    If I had written this definition, I would even have left out functions altogether:

    "A variable object is a container of data associated with the execution context. It’s a special object that stores variables defined in the context."

    Then afterwards one can clarify that

    "Variables are defined by variable declarations, function declarations, and function parameters. Nothing else creates variables."

    Sure, you also have to understand that there is a difference between a function declarations and function expressions, and that it depends on the lexical context which of the two a function keyword creates. This I would however expect in a section on parsing and expression evaluation, not in the discussion of variable objects.