BugHunt

JavaScript debugging exercises

JavaScript is forgiving in the worst way: read past the end of an array and you get undefined, add a number to a string and you get text, forget an await and you get a Promise. The program keeps running and the bug surfaces somewhere else. These exercises train you to trace that kind of failure back to its cause.

Each one is a short function with one bug, the symptom it produces, and tests that pass only once it is fixed. They run in a sandboxed worker in your browser, from array bounds and missing returns up to closures and async race conditions.

See the exercisesFilter and search

How to debug a JavaScript function

  1. Find where the wrong value first appears. undefined and NaN travel: log the inputs and each intermediate value until you reach the first one that is already wrong.
  2. Check the types, not just the values. typeof and Array.isArray tell you whether "5" is a string, and whether that list is really an array.
  3. Read the error message literally. "Cannot read properties of undefined (reading 'name')" means the thing before .name was undefined, not name itself.
  4. For async code, check what is actually awaited. A function that returns a Promise you never awaited finishes later than everything that depends on it.
  5. Rerun every test after the fix. If another case breaks, the fix was in the wrong place.

The exercises

What you will practise

Questions

Does this need Node.js?

No. Your code runs in a sandboxed Web Worker in the browser, isolated from the page.

Which JavaScript do the exercises use?

Plain modern JavaScript: no frameworks, no build step. The bugs are the ones you meet in any codebase, React or Node included.

Is there a certificate?

Yes, free. Fixing 15 easy JavaScript bugs while signed in earns JavaScript Debugging · Level 1, with a verification link for LinkedIn.