Closures interview questions
Practice 39 questions on closures. Each runs in a real in-browser editor with Jest tests and a worked, diagram-backed solution.
39 questions
- EASY
Cancellable Interval
Implement a setInterval wrapper that returns a function which stops the interval when invoked.
15 minJavaScript - EASY
Cancellable Timeout
Implement a setTimeout wrapper that returns a function you can call to cancel the pending callback.
15 minJavaScript - EASY
Compose
Implement a function that composes functions right-to-left so the output of each feeds into the next.
15 minJavaScript - EASY
Cycle
Implement a function that, given several values, returns a function that yields each one in turn and loops forever.
15 minJavaScript - EASY
Debounce
Implement a function that delays invoking another function until a specified period of inactivity has passed.
15 minJavaScriptGoogle · Amazon · Meta - EASY
Make Counter
Implement a factory that takes a starting integer and returns a function that returns the next value on each call.
15 minJavaScript - EASY
Number of Arguments
Implement a function that returns the count of arguments passed to it at call time.
15 minJavaScript - EASY
Once
Implement a function that wraps a callback so it runs at most one time and reuses that result thereafter.
15 minJavaScript - EASY
Typewriter Pacer
Buffer bursty streamed text and emit it one character at a time at a steady cadence, with flush and stop controls.
18 minJavaScript - EASY
useLatest
Implement a hook that returns a ref always holding the newest value, so callbacks and effects can read it without going stale.
15 minJavaScript - MEDIUM
before / after
Implement before and after — cap how many times a function runs, or delay invoking it until the Nth call.
25 minJavaScript - MEDIUM
Console Log History
Implement a wrapper that intercepts console.log calls and records their arguments for later inspection.
25 minJavaScript - MEDIUM
Curry
Implement a function that transforms a multi-argument function into a chain of single-argument calls.
25 minJavaScript - MEDIUM
Curry II
Implement a flexible curry where each call can supply any number of arguments until the original arity is reached.
25 minJavaScript - MEDIUM
Curry IV
PREMIUMExtend curry with placeholder support, so arguments can be supplied in any position across calls.
40 minJavaScript - MEDIUM
Debounce II
PREMIUMExtend debounce with cancel and flush methods to abort or immediately invoke pending calls.
25 minJavaScript - MEDIUM
Debounce III
PREMIUMExtend debounce with a maxWait option that forces a call after a maximum delay even under constant activity.
25 minJavaScript - MEDIUM
Dependency Injection Container
Build a DI container that resolves a service dependency graph, caches singletons, and detects circular dependencies.
25 minJavaScriptGoogle · Microsoft · Uber - MEDIUM
flow
Implement flow — compose functions left to right so each output feeds the next.
25 minJavaScript - MEDIUM
Function.prototype.bind
PREMIUMImplement Function.prototype.myBind — return a new function with a fixed `this` and optional preset arguments.
25 minJavaScript - MEDIUM
Limit
Implement a function that wraps a callback so it runs at most N times and returns the last result thereafter.
25 minJavaScript - MEDIUM
Make Counter II
Implement a factory that returns a counter object with methods to read, increment, decrement, and reset its value.
25 minJavaScript - MEDIUM
Memoize
Implement a function that caches results of a single-argument function so repeat calls return instantly.
25 minJavaScript - MEDIUM
Memoize III
PREMIUMExtend memoize with a custom key resolver and cache controls (.clear() and .delete(key)).
25 minJavaScript - MEDIUM
Mini Jotai Atoms
Build atom-based state with primitive and derived atoms that recompute and notify subscribers on change.
25 minJavaScript - MEDIUM
Mini Redux
PREMIUMBuild a Redux core with createStore, combineReducers, and applyMiddleware over a subscribe/dispatch loop.
25 minJavaScript - MEDIUM
negate / overEvery
Implement negate, overEvery, and overSome — build new predicates by combining existing ones.
25 minJavaScript - MEDIUM
partial
Implement partial and partialRight — pre-fill some of a function's arguments, with placeholder support.
25 minJavaScript - MEDIUM
Promisify
PREMIUMImplement a function that wraps a Node-style error-first callback function so it returns a promise.
25 minJavaScript - MEDIUM
Promisify II
PREMIUMExtend promisify so the wrapped function can override the resolved value via a custom override hook.
25 minJavaScript - MEDIUM
Redux Middleware (Thunk + Logger)
PREMIUMImplement the curried Redux middleware chain with working thunk and logger middleware.
25 minJavaScript - MEDIUM
Signals (signal / computed / effect)
PREMIUMBuild reactive signals with automatic dependency tracking so computed values and effects update on change.
25 minJavaScript - MEDIUM
Singleton
Implement a Singleton class that always hands back the same instance no matter how many times you construct it.
25 minJavaScript - MEDIUM
Sum
Implement a curried sum function that accepts numbers one call at a time and returns the running total when invoked with none.
25 minJavaScript - MEDIUM
Throttle
Implement a function that limits how often a wrapped function can be invoked within a time window.
15 minJavaScriptGoogle · Amazon · Meta - MEDIUM
Throttle II
PREMIUMExtend throttle with cancel and flush methods plus leading and trailing edge options.
25 minJavaScript - MEDIUM
useGetState
Implement a useState variant that also returns a getter for reading the newest state from inside stale closures.
25 minJavaScript - MEDIUM
useTimeout
Implement a hook that runs a callback after a given delay and cleans up when the component unmounts.
25 minJavaScript - HARD
Curry III
PREMIUMImplement a curry helper that turns a variadic function into one that can be called repeatedly with any number of arguments.
40 minJavaScript