DEV Community

Aditya Rawas
Aditya Rawas

Posted on

1

The Journey of JavaScript Code: From Source to Execution

Have you ever wondered what happens when you write JavaScript code? How does the code you type in your editor transform into something your computer can understand and execute? Let’s break it down step-by-step!


1. Writing the Code

Here’s a simple example:

function add(a, b) {  
    return a + b;  
}  

console.log(add(2, 3));  
Enter fullscreen mode Exit fullscreen mode

At this stage, it’s just text. The magic begins when this code reaches a JavaScript engine like V8.


2. Parsing and AST

The first step in execution is parsing. The engine breaks the code into tokens and then generates an Abstract Syntax Tree (AST), a structured representation of the code. This ensures the syntax is valid and prepares the code for further processing.


3. Ignition: The Interpreter

The AST is passed to V8’s Ignition, which converts it into bytecode, a lightweight intermediate format. Bytecode allows quick interpretation and execution, especially for short-lived scripts.


4. TurboFan: The Optimizing Compiler

As the code runs, frequently executed parts (hot spots) are identified. These are compiled into highly optimized machine code by TurboFan, improving performance dramatically.


This combination of Ignition for fast startup and TurboFan for high runtime performance is what makes JavaScript so powerful and efficient. But there’s much more to the story!

👉 To dive deeper into how JavaScript engines handle interpretation, JIT compilation, and machine code execution, check out my full blog here: https://www.adityarawas.in/blogs/from-code-to-execution-javascript-engine-deep-dive/

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay