JavaScript basics: The Execution Context and the Lexical Environment

What is actually happening when code is executed/functions are invoked?

Dan Park
DailyJS
Published in
7 min readApr 6, 2017

--

A lot of the magic of code happens behind-the-scenes when the code is compiled and interpreted.

JavaScript is described as an interpreted language rather than a compiled language like C or Java. The distinction between an interpreted language and a compiled language might be a future blog post. However, much of the discussion for new JavaScript developers on this subject tend to be confused over the compilation step.

Semantically, you have two ways of understanding compilation:

  1. Compilers take the entire program code and “compiles” it into machine code before the code is executed.
  2. Compilation can simply mean making program code digestible for the machine to run it.

The first definition is the traditional definition of what being a compiled language means. After all, if you think about it, if compilation simply means taking program code and making it machine-readable, all languages would be “compiled”. It is under the traditional definition, JavaScript is understood as an interpreted language, where Google’s V8 engine compiles the program code line-by-line just as it is being run —…

--

--

Dan Park
DailyJS

Husband, student of JavaScript, love React! ex-attorney with J.D. from Georgetown Law