DEV Community

Hihi
Hihi

Posted on • Updated on

Javascript compile time and runtime

In this article I will give a brief about Javascript compilation and runtime. I recommend you to elaborate to these terms to have a deep knowledge of how Javascript is run under the hood.

Compile time:

  • The phase when Javascript is parsed into machine code - set of instructions for the machine to do as follow.
  • The compilation process has 3 phases: - Tokenizing/Lexing - Parsing - Code-Generation.
  • All the checking and optimization is done in this compile time.
Runtime:
  • The phase when the code is done compiled and is invoked to execute.
  • In Javascript specifically, the runtime system facilitates storing functions, variables, and managing memory by using data structures such as queues, heaps, and stacks. All these engines are provided by Javascript v8 if you run code in Chrome.
  • Ex: NodeJS and Browser runtime provide all the things need to run our Javascript code. The run kit is comprise of Event loop, callback queue and Javascript engines (heap and callstack).

=> When we type and run the JS code in the console browser, the browser will firstly compile the code into machine code, and then run the byte code (compiled code) in the environment (JS v8) - which means this in runtime. How JS v8 works

Ref:

Top comments (0)