Developer skills
Common coding bugs and how to spot them
Off-by-one loops, NaN and NULL, falsy zero, shared defaults, sorting surprises and forgotten awaits: what goes wrong and the habit that catches each one.
4 min read
Spot the buggy line in short JavaScript, Python and SQL snippets. 8 a round, with the cause and the fix after each.
JavaScriptWhich line has the bug?
Meant to: Add up every number in an array.
function sum(numbers) { let total = 0; for (let i = 0; i <= numbers.length; i++) { total += numbers[i]; } return total;}Fixed
8 short snippets. Each has one line that breaks it. Find the line.
Click the line with the bug, or move with the arrow keys and press Enter. Then press Enter for the next snippet.Tap the line with the bug, then Next snippet.
Most bugs are not exotic. They are the same small mistakes, made again and again: a loop that runs once too often, a comparison with NULL, a default value that is shared between calls. Bug Hunt is practice at spotting them quickly, the way you would in a code review.
Each round has 8 short snippets. Every snippet says what it is meant to do and has exactly one line that stops it doing that. Pick the line. Then you see the bug, why it happens and the fixed line, so every snippet teaches you something even when you miss it.
| Move between lines | Up and Down arrows (Tab reaches the code) |
|---|---|
| Pick a line | Enter or Space, or click it |
| Next snippet | Enter (the Next button has focus) |
| New round | N |
| Sound on or off | M |
| Pick a line | Tap it |
|---|---|
| Next snippet | Tap Next snippet |
Every snippet has exactly one line that causes the problem its description names. The other lines are correct as written. Where a bug shows up on a later line than the one that causes it, the line that counts is the cause: the one you would change to fix it.
Some bugs crash, like a KeyError in Python. Most do not: they quietly give the wrong answer, which is what makes them worth learning to spot.
JavaScript snippets run in a browser or Node.js. Python snippets are Python 3. SQL snippets use standard SQL; where a database behaves differently, the snippet says which one it means.
Each bug you find scores one point, out of 8. There is no clock. A round never repeats a snippet. Your best score and the number of rounds played for each language choice are saved in this browser on this device.
Developer skills
Off-by-one loops, NaN and NULL, falsy zero, shared defaults, sorting surprises and forgotten awaits: what goes wrong and the habit that catches each one.
4 min read
Developer skills
The parts of a regular expression you will use every week, each with a small example, plus the mistakes that catch everyone out.
4 min read
Developer skills
What a branch actually is, what HEAD points to, and what merge, rebase, cherry-pick and reset do to the commit graph.
4 min read
Developer
Write a regular expression that matches every string on one list and none on the other. 24 puzzles, from anchors to lookarounds.
Developer
A typing test for programmers: type real JavaScript, Python, Rust and SQL code against the clock.
Developer
Learn git branching by doing it: type real git commands until your commit graph matches the goal. 12 levels, from commit to rebase.