Skip to main content

JavaScript Debounce — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Debounce lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.

Exercises(5)

  1. 1

    Build a debounce wrapper

    easy10 min

    Write debounce and confirm no call has run yet after several calls.

  2. 2

    Show each call resets the timer

    easy10 min

    Confirm nothing has been received yet after three rapid calls.

  3. 3

    Simulate a search box

    easy10 min

    Type several characters and confirm no search ran yet.

  4. 4

    Simulate rapid resize events

    easy10 min

    Fire many resize calls and confirm layout has not run yet.

  5. 5

    Pass arguments through the wrapper

    medium10 min

    Confirm the debounced function accepts arguments without error.

Find the bug(5)

  1. 1

    Fix the timer never cleared

    easy8 min

    Without clearTimeout, every call schedules its own run instead of collapsing into one.

  2. 2

    Fix the function called immediately

    easy8 min

    The function should be scheduled, not run right away.

  3. 3

    Fix the timer variable shared across instances

    easy8 min

    Two separately created debounced functions should not share one timer — here the second call cancels the first.

  4. 4

    Fix the arguments never forwarded

    easy8 min

    The wrapped function should receive what it was called with.

  5. 5

    Fix the wrapper missing its return

    easy8 min

    debounce must return the wrapped function for it to be usable.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace