JavaScript Internals (521 Qs)•Part 2: Promises, Callbacks, Async & Strict Mode (54 - 103)
Is JavaScript a compiled or interpreted language
JavaScript is an interpreted language, not a compiled language. An interpreter in the browser reads over the JavaScript code, interprets each line, and runs it. Nowadays modern browsers use a technology known as Just-In-Time (JIT) compilation, which compiles JavaScript to executable bytecode just as it is about to run.
Practical Code Example
javascript
// JavaScript is JIT-compiled (Just-In-Time compiled) in modern engines (V8, SpiderMonkey)
// 1. Source code is parsed into an Abstract Syntax Tree (AST)
// 2. Interpreter (Ignition) converts AST to bytecode for immediate execution
// 3. Optimizing compiler (TurboFan) monitors hot functions and compiles them to native machine code:
function add(a, b) {
return a + b; // Hot path compiled directly to assembly instructions
}
for (let i = 0; i < 100000; i++) add(i, 1);