Skip to main content

Command Palette

Search for a command to run...

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

Updated
3 min read
JS Engine Exposed – Google's V8 Architecture (Made Simple!)
P

My name is 𝐏𝐫𝐚𝐤𝐚𝐬𝐡 and I talk about 𝗧𝗲𝗰𝗵-𝐊𝐧𝐨𝐰𝐥𝐞𝐝𝐠𝐞, 𝗪𝗲𝗯𝗗𝗲𝘃, 𝗗𝗲𝘃𝗢𝗽𝘀 and 𝗟𝗶𝗳𝗲𝘀𝘁𝘆𝗹𝗲.


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.