JS Engine Exposed โ Google's V8 Architecture (Made Simple!)


What Makes JS Run? โ The JavaScript Runtime Environment (JRE)
JS needs a special environment to run โ this is called the JavaScript Runtime Environment (JRE).
Think of JRE as a Kitchen:
JS Engine: The chef who cooks your code.
Web APIs: Extra tools like microwave, oven, or fridge (things like DOM, setTimeout, etc.).
Event Loop: The kitchen manager who decides when things get cooked.
Callback & Microtask Queue: Waiting lines for dishes to be cooked.
๐ก Important: Browsers (like Chrome, Firefox) and some platforms (like Node.js) provide this environment so that your JS code can work.
๐ ECMAScript & JavaScript Engines
ECMAScript: It's like a rulebook (standard) that every JS engine follows.
JavaScript Engine: Software that understands and runs your JS code.
Different browsers use different JS engines:
Chrome: V8
Firefox: SpiderMonkey
Safari: JavaScriptCore
Edge: Now uses V8 (used to have Chakra)
What is a JavaScript Engine?
A JS Engine is not a machine. Itโs a program written in low-level languages like C++. Its job is to take your JS code and turn it into something your computer understands โ machine code.
Letโs understand what happens inside.
๐ The 3 Stages of Code Inside JS Engine
When you write JavaScript like:
let a = 5;
The engine processes this in 3 steps:
1. Parsing:
Breaks code into tokens (small parts):
let
,a
,=
,5
.Creates an AST (Abstract Syntax Tree) โ a tree structure that represents your code.
You can try this yourself at astexplorer.net
2. Compilation (Yes, JS Compiles!)
JavaScript uses something called JIT (Just-In-Time) Compilation, which is a mix of:
Interpreter: Quickly runs the code.
Compiler: Optimizes it while it runs.
โ So yes, JavaScript is compiled! It's not just interpreted like in the old days.
๐ The engine compiles and executes at the same time to improve speed.
Example:
function add(a, b) {
return a + b;
}
add(2, 3);
First, interpreter runs it.
If the function is used often, compiler will optimize it on the go!
Extra Reading:
3. Execution:
Once the code is compiled, it's ready to run.
Two important parts during execution:
Memory Heap: Where all variables and objects live.
Call Stack: Keeps track of function calls (Remember this from async JS?).
๐ฎโโ๏ธ Garbage Collector: Cleans up unused memory using a method called Mark and Sweep (marks unused variables and removes them).
V8 Engine โ Behind the Scenes
The V8 Engine (used in Chrome & Node.js) has:
Ignition โ Interpreter
TurboFan โ Optimizing Compiler
Orinoco โ Garbage Collector
This combo helps JS run fast and efficiently.
Want to See This Live?
Watch this full explanation on YouTube by Akshay Saini:
๐ JS Engine Exposed โ Akshay Saini
๐ Final Notes
JavaScript Engines have evolved a lot โ from simple interpreters to smart compilers.
JS is now a JIT compiled language (Best of both worlds).
Knowing how your code runs helps you write better and faster applications.
Subscribe to my newsletter
Read articles from UR Prakash Gupta directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

UR Prakash Gupta
UR Prakash Gupta
My name is ๐๐ ๐๐ซ๐๐ค๐๐ฌ๐ก ๐๐ฎ๐ฉ๐ญ๐ and I talk about ๐ง๐ฒ๐ฐ๐ต-๐๐ง๐จ๐ฐ๐ฅ๐๐๐ ๐, ๐ช๐ฒ๐ฏ๐๐ฒ๐, ๐๐ฒ๐๐ข๐ฝ๐ and ๐๐ถ๐ณ๐ฒ๐๐๐๐น๐ฒ.