JavaScript basics: The Execution Context and the Lexical Environment
What is actually happening when code is executed/functions are invoked?
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:
- Compilers take the entire program code and “compiles” it into machine code before the code is executed.
- 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 —…