Sitemap
Neha Prabhakar

Neha Prabhakar

JavaScript Runtime Environment

3 min readApr 29, 2024

Hi There! Today we will understand the runtime environment of JavaScript what all it includes. Let’s dive deep into and see..

Press enter or click to view image in full size

The above picture shows what browser has JS Engine, API, Event loop, Callback Queue & Microtask Queue. Node.js is an open source JS Runtime Environment and the JS Engine in it is V8. Just a small point we all know that JS engine is not a machine but a code in low-level language. The first JS engine was Spider Monkey now used in Firefox.

Get Neha Prabhakar’s stories in your inbox

Join Medium for free to get updates from this writer.

Now let’s understand the Architecture of JS Engine :

Press enter or click to view image in full size

There are 3 steps, 1st is Parsing in which code is converted to AST (Abstract Syntax Tree) also you can refer to the site it explains how simply coverts the code to AST — astexplorer.net. Refer the image below to understand better:

Press enter or click to view image in full size

Coming to the 2nd step which is the Compilation, it has Just In Time Compilation (JIT Compilation) which will have compiler + interpreter. AST goes to interpreter & executes meanwhile interpreter takes help of compiler to optimize the code.

Interpreter -> when code is converted to byte line by line and is a faster way.
Compiler -> when code is compiled before then optimized version is executed and is more efficient.

The third step is execution which includes interaction with call stack as we know the code is executed there and the memory heap, which in turn has garbage collector which uses algorithm i.e., Mark & Sweep Algo.

Currently the fastest JS Engine is Google V8, its interpreter is called ignition, the compiler is called Turbofan and the Garbage collector is Orinoco. For better understanding refer below image of the architecture of V8 JS Engine.

Press enter or click to view image in full size

Hope this was helpful and easy to understand. If you found this blog helpful please go through my profile and have a look at some other interesting content. See you in next one! :) Until then..

Press enter or click to view image in full size
Photo by Pablo de la Fuente on Unsplash

--

--