DEV Community

Cover image for Quick Overview To JavaScript Engines
Pato
Pato

Posted on • Updated on

Quick Overview To JavaScript Engines

You don't need to know how the JavaScript engines work in order to learn JavaScript but it's always good to learn how things work under the hood.

Keep in mind that every JavaScript gets interpreted differently depending on what engine your browser is using.

JavaScript parsing: This means that your browser reads your javascript code.

JavaScript execution: This is the actual process where our code does something.

When the code is parsed and executed that is when the browsers makes use of the JavaScript engine.

The engine for Google Chrome is called v8, and the one for Firebox its called SpiderMonkey.

For more info on:
Google V8
Firebox SpiderMonkey

Typically the engines have two parts:

-The Interpreter
-The Compiler (Usually a just-in-time compiler) aka JiT

Note: In this post, we will focus on how the engines generally work, not what the engines do when the code executes.

The Interpreter

This is where our engine parses/loads our script (JavaScript code), reads it, then translates it to byte code, and finally starts the execution. The byte code is giving to the compiler.

The Compiler

Compiles your script into machine code. So the translation from JavaScript code to machine code is what our compiler does.

Remember: that just-in-time compilation means that our compiler starts compiling and executing the compiled code.

JavaScript Engine Does Optimization

If you wrote a script and then modified part of it, the JavaScript engine checks what code didn't change between the last execution and the one that is currently running. The current version not always gets re-compiled. The engine checks what code has been compiled and doesn't compile it again, which makes the engine's process faster.

Browser APIs

Our browsers come with default functions or objects that work with our JavaScript code. When we make use of this functions or objects that are in our browser APIs, the engine interprets and compiles our code then the browser knows where are these functions or objects coming are from.

Top comments (1)

Collapse
 
huylong profile image
huylong

Thank you