Search code examples
javascriptcompiler-constructioninterpreterexecutionhoisting

Did Javascript execution context always have two phases (creation and execution)?


In JavaScript Understanding the Weird Parts ,the genesis of a particular execution context was explained in reference to two phases:

  1. Creation phase - declarations are prioritized and initialized with undefined values
  2. Execution phase - where assignments are resolved

In this answer to a related question, the author refers to the interpreter making two passes on the source code.

Has this always been a feature of JS or is it more recent phenomenon related to more modern JS engines which act as JIT compilers?


Solution

  • In general, everything has to be created before it can be used.

    And yes, this has been the behaviour of JavaScript since the first standard edition.

    But no, modern engines are not interpreters that "make two passes on the source code" any more, they use a parser that extracts the declarations and executable commands in a single pass.