Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between JavaScript Engine and JavaScript Runtime Environment

Tags:

javascript

I'm feeling a bit confused, could someone help to describe What is the difference between JavaScript Engine and JavaScript Runtime Environment. BTW, Event Loop was implemented in Engine or Runtime?

like image 715
clark Avatar asked Mar 13 '15 08:03

clark


People also ask

What is JavaScript runtime environment?

JavaScript Runtime Environment (JRE) JRE is responsible for making JavaScript asynchronous. It is the reason JavaScript is able to add event listeners and make HTTP requests asynchronously. JRE is just like a container which consists of the following components: JS Engine. Web API.

What is meant by JavaScript engine?

A JavaScript engine is a software component that executes JavaScript code. The first JavaScript engines were mere interpreters, but all relevant modern engines use just-in-time compilation for improved performance. JavaScript engines are typically developed by web browser vendors, and every major browser has one.

What is V8 JavaScript runtime engine?

V8 is Google's open source high-performance JavaScript and WebAssembly engine, written in C++. It is used in Chrome and in Node. js, among others. It implements ECMAScript and WebAssembly, and runs on Windows 7 or later, macOS 10.12+, and Linux systems that use x64, IA-32, ARM, or MIPS processors.


2 Answers

Unlike C and other compiled languages, Javascript runs in a container - a program that reads your js codes and runs them. This program must do two things

  • parse your code and convert it to runnable commands
  • provide some objects to javascript so that it can interact with the outside world.

The first part is called Engine and the second is Runtime.

For example, the Chrome Browser and node.js use the same Engine - V8, but their Runtimes are different: in Chrome you have the window, DOM objects etc, while node gives you require, Buffers and processes.

like image 132
georg Avatar answered Nov 08 '22 12:11

georg


Imagine a robot is playing a music:

  • The JavaScript code would be the music notes to the robot.
  • TheJavaScript engine would be the robot which can understand the notes and act on it.
  • The JavaScript runtime would be the instruments the robot can use in order to play the music.

Imagine a robot is putting out a fire:

  • The JavaScript code would be the instructions to the robot to put out a fire.
  • The JavaScript engine would be the robot which can understand the instructions and act on it.
  • The JavaScript runtime would be the fire truck, and the water gun.
like image 40
Luo Jiong Hui Avatar answered Nov 08 '22 12:11

Luo Jiong Hui