Skip to content
Sahil Durgia/ full-stack
2 min readInterview Prep

Frontend Machine-Coding Round Prep: Debounce, Throttle, and a Todo App From Scratch

What a machine-coding round actually checks — working code under time pressure — and two implementations you should be able to write cold.

machine codinginterview prepJavaScript

A machine-coding round (build a todo app, implement debounce, build a rate limiter, all live, in 30-45 minutes) is evaluating something different from a system design round: can you turn a spec into working code, under real time pressure, without getting stuck. Two implementations worth being able to write cold.

Debounce — already covered, worth having memorized

The full explanation lives in the closures post in the JavaScript Fundamentals series — worth writing from memory here as the baseline machine-coding check:

function debounce(fn, delay) {
  let timeoutId;
  return (...args) => {
    clearTimeout(timeoutId);
    timeoutId = setTimeout(() => fn(...args), delay);
  };
}

Throttle — the one debounce gets confused with

Debounce waits for a pause before firing once. Throttle fires at most once per fixed interval, regardless of how many calls happen in between — the right tool for a scroll handler, where you want regular updates during continuous scrolling, not just one update after scrolling stops.

function throttle(fn, interval) {
  let lastCall = 0;
  return (...args) => {
    const now = Date.now();
    if (now - lastCall >= interval) {
      lastCall = now;
      fn(...args);
    }
  };
}

The actual evaluation criteria, honestly

  • Does it work for the stated case first — resist the urge to over-engineer edge cases before the happy path is solid and demonstrated.
  • Is state managed cleanly — for a todo app, is the array of todos updated immutably (new array, not mutated in place), which is the same pattern the ES6+ features post covers with spread syntax.
  • Are edge cases handled once asked for, not left silently broken — an empty input, a duplicate item, a network failure if the round includes a fetch.
  • Can you explain your own code while writing it — narrating the plan out loud before typing is a real, strong signal independent of the code itself.

The practical prep advice

Practice building a todo app (add, remove, toggle complete, filter) from a truly blank file, timed, more than once. The value isn't the app — it's removing the friction of "where do I even start" so that friction doesn't eat into the actual interview's limited time.

Runnable example

The snippets above are the short version — the full, runnable code lives on GitHub.

View on GitHub ★