D
DevPrepSystematic Prep
JAVASCRIPT · HARD CODEX

JavaScript Interview Questions — Hard

Deep runtime internals, memory models, distributed design, concurrency failure modes, and architectural decisions.

50 Theory Questions7 Implementation Folios5 Free Model Answers
THEORY QUESTIONS & SOLUTIONSShowing 5 of 50 questions
Q1Explain Memory Management and Garbage Collection in the V8 engine. How are young and old spaces handled?
  • Generational Hypothesis: Most objects die young. V8 divides its heap accordingly:
  • New Space (Young Generation): Holds short-lived objects (1MB - 64MB). Uses Cheney's copying algorithm (Scavenger). Splits memory into active "From" and inactive "To" semispaces. Fast, frequent collections copy surviving objects to the "To" space, swap the spaces, and promote long-surviving objects to the Old Space.
  • Old Space (Old Generation): Holds long-lived objects. Uses the Mark-Sweep-Compact algorithm:
    • Marking: Traverses GC roots (stack, globals, DOM) to recursively mark reachable objects.
    • Sweeping: Iterates unreferenced memory to free unreachable space.
    • Compacting: Shifts remaining active blocks together to eliminate memory fragmentation.
  • Incremental & Concurrent Marking: V8 runs marking in small slices in parallel with main-thread execution to prevent long UI freeze pauses.
Q2How do `WeakMap` and `WeakSet` prevent memory leaks compared to standard collections?
  • Strong References: Standard Map and Set hold strong references to their entries. If an object is used as a key/member, it cannot be garbage-collected, even if all other external references to it are deleted.
  • Weak References: WeakMap and WeakSet hold weak references to their object keys.
  • GC Interaction: If no strong references to a key object remain outside the weak collection, the garbage collector will reclaim the object's memory and automatically destroy the corresponding map entry during the next GC cycle.
  • Use Cases: Storing private DOM element metadata, or memoizing expensive computational results without blocking memory cleanup.
Q3Explain the V8 compilation pipeline: JIT, Ignition, TurboFan, Hidden Classes, and Inline Caches.
  • V8 Pipeline: Source -> AST -> Ignition Interpreter -> Bytecode -> TurboFan Optimizer -> Machine Code.
  • Ignition: Quickly generates lightweight bytecode for rapid initial app startup.
  • TurboFan: Monitors execution profiles. Hot functions with stable parameter types are compiled into native machine code. If parameter types mutate later, TurboFan performs a Deoptimization and falls back to bytecode.
  • Hidden Classes (Shapes): V8 assigns hidden classes to objects. If objects add identical properties in the same order, they share a shape, allowing JIT to locate properties via memory offsets rather than slow hash lookups.
  • Inline Caches (ICs): ICs speed up property lookups by caching physical memory offsets of properties mapped to specific object shapes directly at the property access call site.
Q4Detail the Binary Data Pipeline and Stream architecture in modern JS.
  • ArrayBuffer: Represents a fixed-length, contiguous block of raw binary data. Cannot be read or modified directly.
  • TypedArrays: Views (e.g., Uint8Array, Float64Array) providing typed numeric read/write capabilities on an ArrayBuffer.
  • DataView: A flexible view capable of reading/writing heterogeneous numeric types at arbitrary byte offsets inside an ArrayBuffer, with explicit Big-Endian/Little-Endian control.
  • Blob: Immutable container for raw, file-like binary data.
  • Streams API: Processes data incrementally (in chunks) to reduce memory footprints:
    • ReadableStream: Emits chunks of incoming data (e.g., active fetch payloads).
    • WritableStream: Directs sequential data chunks to a target destination.
    • TransformStream: Connects readable and writable streams, modifying chunks mid-transit.
Q5Explain the Proxy and Reflect APIs. How do they build reactivity?
  • Proxy: Wraps a target object and intercepts low-level meta-operations (e.g., get, set, deleteProperty, apply).
  • Reflect: A global object providing static methods that match every Proxy trap. Replaces older object manipulations, handles receiver context binding, and returns boolean statuses rather than throwing exceptions on failures.
  • Reactivity Pattern (e.g., Vue 3):
    • Get trap: Track dependencies. Records the active execution context (the "effect") as a dependent of that property.
    • Set trap: Trigger updates. Runs all recorded dependent effects when the property value changes.

Unlock the remaining 52 JavaScript (Hard) questions

You've completed the 5 free sample questions. Get unrestricted lifetime access to every question, model answer, implementation challenge, and all 27+ technologies for a single payment.

₹399 India / $9 International · One-time settlement · Zero subscription

CROSS-DIFFICULTY NAVIGATION

Continue Preparing JavaScript

JavaScript Interview Questions (Hard) | DevPrep | DevPrep