Engine and Runtime Play Together
- Line 1 through 3 is a function declaration with name
printDateTimetakes no parameters.
- Line 2 is a call to the
consoleobject with one parameter.
new Date()in line 2 is a call to an object constructor.
- The string
Current Date/Time isand the output object from
new Date()will be appended.
- Line 5 and 6 are declarations and assignments of two variables with two different values.
- Line 7 is a call to the
setTimeoutfunction with two parameters.
All of the above are job of an engine. But what does browser or any other runtime do? They provide APIs to communicate with the external world. Provide APIs for the common functionalities. These APIs are mostly implemented with low-level languages like C/C++. Basically provided APIs define the functionalities of the platform. A browser provides APIs those are applicable for a program to run in a browser. Browser APIs are like DOM manipulation APIs, windows and document APIs. On the other hand, Node.js provides APIs those are applicable for a server application. Such APIs are like require, process, and buffer APIs.
Engine and runtime work together. Engine manages everything to generate machine instructions. The runtime provides APIs to communicate with external world like browser console, DOM, or Geolocation device. In the next article I’ll focus on the engine.
Articles in this series
- Engine vs Runtime