DEV Community

Hihi
Hihi

Posted on • Edited on

Javascript compile time and runtime

In this article I will give a brief about Javascript compilation and runtime. I recommend you to elaborate to these terms to have a deep knowledge of how Javascript is run under the hood.

Compile time:

  • The phase when Javascript is parsed into machine code - set of instructions for the machine to do as follow.
  • The compilation process has 3 phases: - Tokenizing/Lexing - Parsing - Code-Generation.
  • All the checking and optimization is done in this compile time.
Runtime:
  • The phase when the code is done compiled and is invoked to execute.
  • In Javascript specifically, the runtime system facilitates storing functions, variables, and managing memory by using data structures such as queues, heaps, and stacks. All these engines are provided by Javascript v8 if you run code in Chrome.
  • Ex: NodeJS and Browser runtime provide all the things need to run our Javascript code. The run kit is comprise of Event loop, callback queue and Javascript engines (heap and callstack).

=> When we type and run the JS code in the console browser, the browser will firstly compile the code into machine code, and then run the byte code (compiled code) in the environment (JS v8) - which means this in runtime. How JS v8 works

Ref:

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)

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay