JavaScript
/Advanced
JavaScript Runtime
Definition
The complete environment that provides the necessary tools for JavaScript code to be executed. The JS Engine (V8) is just one part of the Runtime.
Explain Like I'm New
The JS Engine (V8) is just a translator that turns JS into machine code. It has no idea what `setTimeout`, `document.getElementById`, or `fs.readFile` are. The Runtime (the Browser or Node.js) is the giant factory that surrounds the translator, providing those Web APIs and managing the Event Loop.
Real World Example
Chrome, Node.js, Deno, and Bun are all different Runtimes. They all use a JS Engine (Chrome/Node/Deno use V8, Safari uses JavaScriptCore), but they provide completely different APIs. Node.js provides `fs` for files, the Browser provides `window` for the UI.
Common Use Cases
- •Understanding cross-environment compatibility (Isomorphic JS)
Terminal Output
bash / terminal
// This is pure JavaScript (Handled entirely by V8 Engine)
const sum = 1 + 1;
// This is a Runtime API (Handled by the Browser/Node.js)
// In the browser, it hooks into the C++ DOM API.
// In Node, this crashes because 'document' does not exist in the Node runtime.
/* document.getElementById('app'); */
Interview Questions
basic
- What is the difference between V8 and Node.js?
intermediate
- Why does `window` exist in the browser but throw an error in Node.js?
advanced
- What library handles the Event Loop and Async I/O in Node.js?