Beruflich Dokumente
Kultur Dokumente
Work? (Part 1)
What is V8 and what happens under the hood when
JavaScript runs?
ECMAScript
One question arises from the huge list of engines; Can I make
my own engine? Yes, just follow the ECMAScript standard.
The V8 engine
Some history
Google created Google Maps for the browser which required a
lot of processing power. The JavaScript implementation at that
time was not good enough to run maps fast. Google wants to
bring more users to their services so that they can sell more
advertisements and make money. For this, the service needs to
be fast and robust. So Google built its own engine called the V8
in C++ which was launched in 2008 and quite fast or as some
say the fastest.
Parsing and building the tree
The JavaScript file enters the engine and the parser does lexical
analysis which breaks the code into tokens to identify their
meaning. These tokens make the AST(Abstract Syntax
Tree).
The ASTs play a critical role in the semantic analysis where the
compiler validates the correct usage of the language elements
and keywords. Later on, the ASTs are used to generate the
actual bytecode or machine code.
JavaScript to AST using astexplorer.net
Conclusion
There are a lot of implementations of the ECMAScript engines
and V8 by Google is the most famous one. I hope this article
succeeded in giving you a brief overview of not only how
JavaScript works, but also in general how a programming
language works. If you want to know what are the future plans
of the V8 team or want even more details on the engine, they
have a wonderful blog here.