BugHunt

JavaScript loop exercises

A loop that runs one step too far in JavaScript does not crash: it reads undefined and carries on, and the wrong value shows up somewhere else. These exercises are short loops with one bug each, from bounds and stop conditions to closures and async.

Infinite loops are stopped safely after a few seconds, so experiment freely.

See the 19 exercisesOr follow the 30-day path

The loops bugs you will meet

The exercises

Errors you might be searching for

More JavaScript practice by topic

Questions

What if my fix loops forever?

The test is stopped after a few seconds and marked as timed out, and the page keeps working.

Can I step through the loop?

Yes. After a run, the line-by-line view shows each variable on every pass.