Script Valley
Debugging: A Systematic Approach
Reading Code to Find Bugs/Assessment

Practice & Assessment

Test your understanding of Reading Code to Find Bugs

Multiple Choice Questions

5
1

What does this Python code print on the second call to add_item(2)? def add_item(item, lst=[]): lst.append(item); return lst

2

You run: for (var i = 0; i < 3; i++) { setTimeout(() => console.log(i), 0); }. What prints?

3

What is the purpose of git bisect in debugging?

4

A function has a less-than-or-equal sign in a loop condition iterating over an array. Why is this suspicious?

5

During a defensive code review you find: const user = db.find(id); return user.name. What is the hidden assumption?

Coding Challenges

1
1

Find Five Bugs by Reading, Not Running

A JavaScript file containing five functions is provided. Each function has exactly one bug. You may NOT run the code. Read each function, apply the defensive reading checklist (null checks, boundary conditions, type assumptions, all exit paths), and produce a list of: function name, bug description, line number, and one-line fix. Input: provided source file. Output: a structured list of five bug reports. Time estimate: 25 minutes.

Medium

Mini Project

1

Bug Pattern Cheat Sheet

Create a living reference document containing at least 8 distinct bug patterns across JavaScript and Python. For each pattern, provide: pattern name, one-line description of the failure mechanism, a minimal code example that exhibits the bug (under 6 lines), the correct fix, and one real-world scenario where this pattern commonly occurs. The document must be structured for quick scanning during code review.

Medium
Practice & Assessment โ€” Reading Code to Find Bugs โ€” Debugging: A Systematic Approach โ€” Script Valley โ€” Script Valley