DEV Community

Aditya Vivek Thota
Aditya Vivek Thota

Posted on β€’ Originally published at Medium on

How does your web browser run Javascript?

A quick summary


Photo by Claudio Schwarz on Unsplash

Questions on web browsers are frequently asked in interviews. For example, the process of loading a webpage in a browser from the moment a URL is entered is one of the most asked interview questions.

Here, let’s talk specifically about how JavaScript (JS) runs.

JS is a client-side scripting language. This means your browser (aka the client) runs it. How?

Every browser comes with a JS Engine which also acts like a virtual machine that helps us run the code.

Did you know that different browsers use different JS engines?

πŸ‘‰πŸ» Chrome uses V8

πŸ‘‰πŸ» Edge uses Chakra

πŸ‘‰πŸ» Firefox uses Spider monkey

Here’s a simplified summary of what happens:

  • The JS engine locates the script/JS code, checks the syntax, and parses it into an Abstract Syntax Tree (AST). Think of it as a tree-like representation of the code. This step is done by a β€œ parser ”.
  • The AST is converted into bytecode and run by an interpreter. In the case of the V8 engine, the interpreter is called β€œ ignition ”.
  • The bytecode and the profiling data generated while running it is passed to a Just in time (JIT = compilation during runtime) compiler that can produce highly optimized machine code.
  • In the case of the V8 engine, the compiler is called β€œ Turbofan ”.
  • In the case of Chakra and Spider monkey, there are some differences in these steps and they use two optimizing compilers.

The rest of the steps and architecture in most JS engines are similar.

I hope you got a good overview.

Here are some links for more in-depth exploration:

This content was first published by me here.


Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

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

Okay