How to Execute JavaScript Code ? Last Updated : 15 May, 2023 Comments Improve Suggest changes Like Article Like Report 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. Comment More infoAdvertise with us Next Article How to Execute JavaScript Code ? V vikas2pandey020 Follow Improve Article Tags : JavaScript Web Technologies Advanced Javascript JavaScript-Questions Similar Reads How to execute jQuery Code ? jQuery is an open-source feature-rich Javascript library that is designed for the simplification of HTML DOM Tree traversal & manipulation, event-handling & CSS animation. It is quite popular for its features like light-weight, fast, small, etc, that make it easier to use. The purpose of usi 4 min read How to Execute JavaScript After Page Load? When a webpage loads, it takes time. The browser reads the HTML, builds the Document Object Model (DOM), and starts rendering the page. If your JavaScript runs too early, it might try to change elements that aren't ready yet, causing errors. Running JavaScript after the page loads makes sure all the 5 min read How to convert CoffeeScript code in JavaScript ? CoffeeScript is a lightweight programming language that compiles into JavaScript. It provides simple and easy-to-learn syntax, avoiding the complex syntax of JavaScript. CoffeeScript is influenced by JavaScript, Ruby, YAML, Haskell, Perl, and Python and has influenced MoonScript, LiveScript, and Jav 2 min read How to Enable JavaScript on Android ? JavaScript is the world's most popular lightweight, interpreted compiled programming language. It is also known as a scripting language for web pages. It is well-known for the development of web pages, many non-browser environments also use it. Therefore nowadays it is essential for users to have Ja 2 min read Introduction to JavaScript JavaScript is a versatile, dynamically typed programming language used for interactive web applications, supporting both client-side and server-side development, and integrating seamlessly with HTML, CSS, and a rich standard library.JavaScript is a single-threaded language that executes one task at 7 min read How to Add JavaScript in HTML Document? To add JavaScript in HTML document, several methods can be used. These methods include embedding JavaScript directly within the HTML file or linking an external JavaScript file.Inline JavaScriptYou can write JavaScript code directly inside the HTML element using the onclick, onmouseover, or other ev 3 min read How to enable JavaScript in my browser ? We will explore the process of enabling JavaScript in web browsers to ensure seamless functionality of applications and websites. JavaScript serves as a fundamental component of modern web development, facilitating dynamic interactions and enhanced user experiences. However, encountering issues wher 2 min read How to Detect Keypress using JavaScript ? In this article, keyboard detection is performed using HTML and CSS. HTML stands for "Hypertext Markup Language". HTML language helps the developer to create and design web page elements like links, sections, paragraphs, headings, and blockquotes for web applications. CSS stands for "Cascading Style 2 min read Is JavaScript Interpreted or Compiled ? JavaScript is an interpreted language. To understand this better, let's look at interpreters, compilers, and JIT (Just-In-Time) compilers: 1. Interpreter: An interpreter runs instructions directly from the programming language without changing them into machine code first. 2. Compiler: A compiler ch 2 min read How to use Ejs in JavaScript ? EJS or Embedded Javascript Templating is a templating engine used by Node.js. The template engine helps to create an HTML template with minimal code. Also, it can inject data into the HTML template on the client side and produce the final HTML. Installation StepsInstall the module using the followin 3 min read Like