Facebook Pixel

JavaScript Engine Interview Questions

JS engines are a common interview topic. Here are the most asked questions about V8, JIT, and GC.

JavaScript Engine Interview Questions

JS engines (especially V8) are a common interview topic for senior roles. Here are the most asked questions with answers.

Q1: What is a JavaScript engine?

A program that takes JS source code and executes it. It parses the code into an AST, compiles it (JIT), and executes it on a call stack while managing memory on a heap. Examples: V8 (Chrome, Node.js), SpiderMonkey (Firefox), JavaScriptCore (Safari).

Q2: What is JIT compilation?

Just-In-Time compilation: the engine compiles code at runtime, not ahead of time. V8 uses Ignition (interpreter) for fast startup and TurboFan (optimizing compiler) for hot code. This balances startup speed and peak performance.

Q3: What are hidden classes in V8?

Internal labels assigned to objects based on their shape (property names and order). Objects with the same hidden class share optimized code. Different shapes cause deoptimization.

Q4: What is deoptimization?

When TurboFan's assumptions break (e.g., a function receives a different hidden class than expected), V8 discards the optimized machine code and falls back to Ignition bytecode. Performance drops until re-optimization.

Q5: What is inline caching?

V8 caches the memory location of a property accessed in a hot function. Next time, it directly reads from the cached location (fast). If the hidden class changes, the cache is invalidated and the function deoptimizes.

Q6: How does V8's garbage collector work?

Generational mark-and-sweep (Orinoco). Young generation: collected frequently (scavenge). Old generation: collected less frequently (mark-sweep-compact). Orinoco is incremental and concurrent to minimize pauses.

Q7: Is the event loop part of the JS engine?

No. The event loop is part of the host environment (browser or Node.js/libuv). The engine (V8) provides the call stack and heap. The host provides the event loop, Web APIs, and queues.

Q8: Is JavaScript compiled or interpreted?

Both. Modern JS engines use JIT compilation: they interpret (Ignition) and compile (TurboFan) at runtime. It is not purely interpreted (like old engines) and not purely compiled (like C++).

Q9: What is the difference between the call stack and the heap?

The call stack tracks function calls (LIFO, one at a time). Primitives are stored on the stack. The heap stores objects and arrays (managed by the GC). Variables hold references to heap objects.

Q10: How can you help V8 optimize your code?

Initialize all properties in the constructor (same order), do not add or delete properties after construction, keep functions monomorphic (same argument types), avoid eval/with/delete, and use arrays for contiguous numeric data.

The Takeaway

JS engine interview questions test: the engine definition (parse, compile, execute), JIT compilation (Ignition + TurboFan), hidden classes, inline caching, deoptimization, GC (generational, Orinoco), the event loop (part of the host, not the engine), compiled vs interpreted, stack vs heap, and optimization tips.

Both. Modern JS engines use JIT (Just-In-Time) compilation: they interpret bytecode (Ignition) for fast startup and compile hot code to machine code (TurboFan) for performance. It is not purely interpreted or purely compiled.

Internal labels assigned to objects based on their shape (property names and order). Objects with the same hidden class share optimized code. Different shapes cause deoptimization, which hurts performance. Keep object shapes consistent.

No. The event loop is part of the host environment (browser or Node.js/libuv). V8 provides the call stack and heap. The host provides the event loop, Web APIs, and queues for async behavior.

Generational mark-and-sweep (Orinoco). Young generation collected frequently (scavenge). Old generation collected less frequently (mark-sweep-compact). Incremental and concurrent to minimize pauses.

Initialize all properties in the constructor (same order), do not add or delete properties after construction, keep functions monomorphic (same argument types), avoid eval/with/delete, and use dense arrays for contiguous numeric data.

Ready to master React completely?

Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.

Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.