D
DevPrepSystematic Prep
JAVASCRIPT · MEDIUM CODEX

JavaScript Interview Questions — Medium

Real-world mechanisms, state management, edge cases, performance trade-offs, and practical coding.

50 Theory Questions7 Implementation Folios5 Free Model Answers
THEORY QUESTIONS & SOLUTIONSShowing 5 of 50 questions
Q1Explain the Event Loop architecture in detail. Describe execution priority between Macrotasks, Microtasks, and Browser Rendering.
  • Event Loop: Monitors the Call Stack. If the stack is empty, it flushes the Microtask Queue before running the next Macrotask.
  • Macrotasks: Timer callbacks (setTimeout, setInterval), I/O, UI rendering events, setImmediate (Node).
  • Microtasks: High-priority callbacks (Promise.then/catch/finally, MutationObserver, queueMicrotask, process.nextTick in Node).
  • Execution Priority:
    1. Run a single Macrotask (e.g., initial script file execution).
    2. Run all microtasks in the Microtask Queue until it is completely empty. New microtasks added during execution are also run in the same cycle.
    3. Perform browser rendering updates (layout, paint, style recalculation) if a frame refresh is scheduled.
    4. Move to the next Macrotask in the queue.
Q2How does Prototypal Inheritance work? Compare `__proto__` and `prototype`.
  • Prototypal Inheritance: Objects inherit properties and methods from other objects via a prototype chain. When accessing a property, JS travels up __proto__ links until it finds the property or reaches null.
  • __proto__: An accessor property on object instances pointing to their active prototype link (used for runtime lookup).
  • prototype: A property that exists only on constructor functions and classes. It becomes the __proto__ of any instance created with new.
  • ES6 Classes compilation: Syntactic sugar over prototype delegation. It compiles to constructor functions with methods attached to .prototype.
Q3How is the `this` keyword resolved at runtime? List the exact priority rules.
  • Definition: this refers to the execution context. Its value is determined at call-time based on the following rules:
    1. new Binding: If called with new, this points to the new instance.
    2. Explicit Binding: If called with .call(), .apply(), or .bind(), this points to the specified object.
    3. Implicit Binding: If called as a method (e.g., obj.method()), this points to obj.
    4. Default Binding: If called stand-alone, this is undefined in strict mode, or the global object (window/global) in non-strict mode.
    5. Arrow Functions: Bypass these rules; they inherit this lexically from their outer block scope.
Q4Explain Lexical Scoping and Closures under the hood. How does the execution context maintain references?
  • Lexical Scoping: The scope of a variable is determined by its physical position in the source code during compiling, not execution.
  • Execution Context: Consists of a Variable Environment and a Lexical Environment. When a function is invoked, its execution context is pushed onto the call stack.
  • Closure under the hood: When a function returns an inner function, the inner function holds a reference to the outer Lexical Environment via [[Scopes]]. This prevents the garbage collector from freeing the memory of the outer environment, maintaining access to outer variables.
Q5What is Currying? How does it differ from Partial Application?
  • Currying: A functional programming pattern that transforms a function taking multiple arguments f(a, b, c) into a chain of nested unary functions returning one another, e.g., f(a)(b)(c).
  • Partial Application: Fixing a subset of arguments on a function, returning a new function that takes the remaining arguments, e.g., converting f(a, b, c) into g(b, c) by pre-filling a.

Unlock the remaining 52 JavaScript (Medium) 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 (Medium) | DevPrep | DevPrep