
When I was preparing for interviews, I collected hundreds of frontend coding questions into a giant spreadsheet. At some point I noticed something: the same ten or so questions kept showing up, just with different names and small twists.
Even better, those ten questions really come down to four patterns. Once you understand the pattern, a new variation stops being scary.

Pattern 1: Closures and timers
These questions test whether you understand that a function can hold onto private state between calls. That’s a closure.
1. Debounce
Run a function only after calls have stopped for wait milliseconds. Classic use: search input.
function debounce(fn, wait) {
let timer;
return function (...args) {
clearTimeout(timer);
timer = setTimeout(() => fn.apply(this, args), wait);
};
}
What interviewers check: did you preserve this and the arguments? Then they’ll ask follow-ups like “add a cancel method” or “support a leading-edge call”. Practice the progression with Debounce I, II, and III.
2. Throttle
Run a function at most once every wait milliseconds. Classic use: scroll and resize handlers. If you mix up debounce and throttle, read debounce vs throttle.
3. Memoize
Cache results by arguments. The interesting part is the cache key. JSON.stringify(args) works for simple values, but fails for functions and treats objects with the same content as equal. Mention that trade-off out loud.
4. Once
Make a function run only once and return the first result on every later call. Small, but it shows up as a warm-up surprisingly often. Try it with Run Once.
Pattern 2: Promises and async control
These questions test whether you can coordinate multiple async operations. They’re also where most candidates make mistakes, so this is where I’d spend the most time.
5. Promise.all
function promiseAll(items) {
return new Promise((resolve, reject) => {
const results = new Array(items.length);
let remaining = items.length;
if (remaining === 0) return resolve(results);
items.forEach((item, i) => {
Promise.resolve(item).then((value) => {
results[i] = value; // keep input order, not completion order
remaining -= 1;
if (remaining === 0) resolve(results);
}, reject); // first rejection wins
});
});
}
The three things interviewers look for: results are in input order (not completion order), the empty array resolves immediately, and non-promise values are handled with Promise.resolve. Then they’ll ask you to implement allSettled, race, or any. Practice with Promise Methods.
6. Retry with backoff
Call an async function, and if it fails, retry up to N times with increasing delays. Good follow-ups: only retry certain errors, add jitter, make it cancellable with an AbortSignal.
7. Concurrency limit
Run 100 async tasks, but at most 3 at a time. This one separates people quickly. The trick is to start limit workers that each pull the next task from a shared index until there are none left.
async function mapWithLimit(items, limit, fn) {
const results = new Array(items.length);
let next = 0;
async function worker() {
while (next < items.length) {
const i = next++;
results[i] = await fn(items[i], i);
}
}
const workers = Array.from({ length: Math.min(limit, items.length) }, worker);
await Promise.all(workers);
return results;
}
This works because JavaScript is single-threaded: next++ can’t be interrupted between reading and incrementing. Saying that out loud is a nice touch. Practice with Async Map with Limit.
Pattern 3: Recursion on nested data
8. Flatten an array
Easy to start, and the follow-ups add a depth argument or ask for an iterative version with a stack. Know both.
9. Deep clone (and deep equal)
The basic version recurses over arrays and plain objects. The senior version talks about what breaks: circular references (use a WeakMap of already-copied objects), Date, Map, Set, and class instances. Also mention that structuredClone exists in modern browsers and handles circular references, but not functions or DOM nodes.
Pattern 4: Small data structure design
10. Event emitter
class EventEmitter {
#listeners = new Map();
on(event, fn) {
if (!this.#listeners.has(event)) this.#listeners.set(event, new Set());
this.#listeners.get(event).add(fn);
return () => this.off(event, fn); // return an unsubscribe function
}
off(event, fn) {
this.#listeners.get(event)?.delete(fn);
}
once(event, fn) {
const off = this.on(event, (...args) => {
off();
fn(...args);
});
return off;
}
emit(event, ...args) {
// copy first, so listeners that unsubscribe during emit don't break iteration
[...(this.#listeners.get(event) ?? [])].forEach((fn) => fn(...args));
}
}
That copy in emit is the detail I’d listen for as an interviewer. Without it, a once listener removing itself mid-loop can cause subtle bugs.
An LRU cache is the other classic here. In JavaScript, a Map keeps insertion order, so you can delete and re-insert a key to mark it as recently used, and evict map.keys().next().value when you’re over capacity.
How to practice these properly
- Write it, then test it. Knowing the solution is maybe 25% of passing. The other 75% is handling edge cases and explaining your code. I recommend solving each one in the FrontendLead editor, which runs real unit tests against your code.
- Re-solve from a blank file a few days later. If you can’t, you memorized it instead of understanding it.
- Practice the follow-up, not just the base question. The interviewer almost always extends the problem.
- Talk while you code. Silence makes interviewers nervous, even when your code is right.
If you want the full list, I put together the top 75 JavaScript questions in the free JavaScript interview questions guide, and all of them can be practiced in the coding questions section.
And that’s it, folks. Ten questions, four patterns. Master the patterns and you’ll recognize the next variation the moment you read it.
