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.nextTickin Node). - Execution Priority:
- Run a single Macrotask (e.g., initial script file execution).
- Run all microtasks in the Microtask Queue until it is completely empty. New microtasks added during execution are also run in the same cycle.
- Perform browser rendering updates (layout, paint, style recalculation) if a frame refresh is scheduled.
- 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 reachesnull. __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 withnew.- 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:
thisrefers to the execution context. Its value is determined at call-time based on the following rules:newBinding: If called withnew,thispoints to the new instance.- Explicit Binding: If called with
.call(),.apply(), or.bind(),thispoints to the specified object. - Implicit Binding: If called as a method (e.g.,
obj.method()),thispoints toobj. - Default Binding: If called stand-alone,
thisisundefinedin strict mode, or the global object (window/global) in non-strict mode. - Arrow Functions: Bypass these rules; they inherit
thislexically 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)intog(b, c)by pre-fillinga.
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