Wednesday, July 3, 2024
HomeLanguagesJavascriptHow to Execute JavaScript Code ?

How to Execute JavaScript Code ?

Javascript is a high-level, Just In Time compiled programming language which converts the entire machine code at once and then executes it immediately. Javascript code is executed by the Javascript Engine, which is separate software. Different browsers have their own implementation of JS Engine embedded in the browser like Google Chrome’s V8 Engine, Mozilla Firefox’s Spider Monkey, Safari’s SquirrelFish, and so on. Let’s explore how Google’s V8 Engine works.

JavaScript Code first goes into the Parser

  • Parser – It reads the JavaScript Code and parses it into a Data Structure called AST (Abstract Syntax Tree). AST is built by breaking down code into tokens and checks for the semantic and syntactic errors in the code. This tree is later used to generate machine code. Below is an example how what AST looks like. (Note – Actual AST looks more complex, this is just to explain to you easily).
  • Compilation / Execution – As mentioned earlier, Javascript is Just in timed Compiled language that makes use of both Interpreter and Compiler. Firstly, the generated AST goes to the Interpreter (Google called it Ignition) which provides the machine code. This machine code is now executed with the help of Call Stack. While the machine code is executing, the Compiler (Google called it Turbo Fan) tries to optimize the code and returns optimized machine code that will run later. The process of compilation and execution of code goes hand in hand.
  • Optimization – JS Engine first create a very unoptimized version of machine code so that execution of code can start as soon as possible. But in the background, the code is being optimized during already running program execution.

Note: As of now, Google’s V8 engine is the fastest Javascript Engine.

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Nicole Veronica Rubhabha
Nicole Veronica Rubhabha
A highly competent and organized individual DotNet developer with a track record of architecting and developing web client-server applications. Recognized as a personable, dedicated performer who demonstrates innovation, communication, and teamwork to ensure quality and timely project completion. Expertise in C#, ASP.Net, MVC, LINQ, EF 6, Web Services, SQL Server, MySql, Web development,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments