Introduction to Javascript Engines - GeeksforGeeks

21 Sep, 2021
JavaScript is not understandable by computer but the only browser understands JavaScript. So, we need a program to convert our JavaScript program into computer-understandable language. A JavaScript engine is a computer program that executes JavaScript code and converts it into computer understandable language.
List of JavaScript Engines:
Let’s understand each of them.
1. V8: V8 is a JavaScript engine developed by the Chromium Project for Google Chrome and Chromium web browsers. It is a JavaScript engine that can run standalone, or be embedded into any C++ application. Using its own parser, it generates an abstract syntax tree. Then, Ignition generates bytecode from this syntax tree using the internal V8 bytecode format. Bytecode is compiled into machine code by TurboFan. It also handles memory allocation for objects, and garbage collects objects it no longer needs. Optimization techniques such as elision of expensive runtime properties, and inline caching. The garbage collector is a generational incremental collector.
V8 provides an edge as it allows JavaScript to run much faster, which improves users’ experience of the web, paves the way for the development of web applications, and spurs rapid growth of server-side JavaScript through projects like Node.js.
2. Chakra: Chakra is a JScript engine developed by Microsoft. It is proprietary software. It is used in the Internet Explorer web browser. A distinctive feature of the engine is that it JIT compiles scripts on a separate CPU core, parallel to the web browser.
3. Spider Monkey: SpiderMonkey is the first JavaScript engine, written by Brendan Eich at Netscape Communications, later released as open-source and currently maintained by the Mozilla Foundation. It is still used in the Firefox web browser.
4. Webkit: WebKit is developed by Apple and  used in its Safari web browser, as well as all iOS web browsers. It is  used by the BlackBerry Browser, PlayStation consoles beginning from the PS3, the Tizen mobile operating systems, and a browser included with the Amazon Kindle e-book reader. WebKit’s C++ application programming interface (API) provides a set of classes to display Web content in windows and implements browser features such as following links when clicked by the user, managing a back-forward list, and managing a history of pages recently visited.
Example 1: Executing JavaScript code by using console: For Nashorn engine, Java 8 introduced one new command-line tool i.e.jjl. We have to follow the below steps to execute JavaScript code through the console:
Create a file named with geeksforgeeks.js.
Open geeks.js and write following code into the file and save it.
 
Javascript
<script>  var gfg= function(){    print("Welcome to Geeksforgeeks!!!");};gfg();  </script>
Output:
Welcome to Geeksforgeeks!!!
Example 2: Executing JavaScript file by embedding JavaScript file into Java code with the help of ScriptEngine class:  By the help of the ScriptEngine class, we can create a JavaScript engine and with the JavaScript engine, we can execute the javaScript file.
// Program to show usecase of Javascript // prog in Java Progimport javax.script.*;import java.io.*;  public class Geeksforgeeks {    public static void main(String[] args)    throws Exception {          // Generating Nashorn JavaScript Engine        ScriptEngine ee = new ScriptEngineManager()                         .getEngineByName("Nashorn");                    // Directly use JS Code  inside Java Code        ee.eval("print('Welcome to Geeksforgeeks!!!')");    }}
Output: 
You might get a Runtime Error like
Warning: Nashorn engine is planned to be removed from a future JDK release
This is because Nashorn is going to be replaced by GraalVM.
 GraalVM:  It is a high-performance runtime that ameliorates application performance and efficiency. It is designed for applications written in various programming languages like Java, JavaScript, LLVM-based languages such as C and C++, and other dynamic languages. It removes the isolation between programming languages and enables interoperability in a shared runtime
Blogathon-2021
JavaScript-Questions
Blogathon
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Import JSON Data into SQL Server?
How to Create a Table With Multiple Foreign Keys in SQL?
How to Install Tkinter in Windows?
SQL Query to Create Table With a Primary Key
SQL Query to Convert Datetime to Date
Convert a string to an integer in JavaScript
Difference between var, let and const keywords in JavaScript
How to calculate the number of days between two dates in javascript?
Differences between Functional Components and Class Components in React
How to append HTML code to a div using JavaScript ?