Compiler and Interpreter
Differences between interpreters and compilers in JS engines and why both are used.
Short explanation
Engines often start with an interpreter for quick startup and then JIT-compile frequently-run code for speed. Interpreters execute code directly from bytecode, while compilers produce optimized machine code.
Small snippet
function fib(n) {
if (n < 2) return n;
return fib(n - 1) + fib(n - 2);
}
console.log(fib(10));
How JS handles it internally
- The interpreter runs bytecode quickly while gathering type/profile info.
- The compiler uses collected data to produce optimized code paths and may deoptimize if assumptions are invalidated.
Diagram

Related
π Related:
FAQ
Q: What is deoptimization?
A: Deoptimization is when JIT-compiled code assumptions are violated (like unexpected types) and the engine falls back to a safe execution mode.