Lesson 6 of 6 · 12 min · 1 hands-on step

Code Review: Find the Bugs in This Pull Request

Review a realistic pull request, catch the bugs, and fix them.

What reviewers look for, in order

  1. Correctness: does it do what the description says? Edge cases? Errors?
  2. Safety: does it change things it shouldn't (mutating inputs, global state)? Any security issues?
  3. Tests: are the important behaviors covered?
  4. Readability: clear names, small functions, no clever tricks
  5. Style: formatting and conventions (often automated by linters)

Write kind, specific comments

❌ Unhelpful ✅ Helpful
"This is wrong." "Unknown codes are silently ignored. Should we throw so the UI can show 'Invalid coupon'?"
"Use a copy." "result = cart mutates the caller's object. { ...cart } would avoid surprising callers."
"Bad name." "Maybe discountedSubtotal? x was hard to follow."

Ask questions instead of giving orders, explain why, and point out what's good too.

Being reviewed

  • Keep PRs small: under ~300 lines gets better reviews
  • Write a clear description: what, why, how to test
  • Don't take comments personally. Review is about the code, and it's how everyone (seniors included) gets better.

Reviewing AI-generated code uses exactly the same checklist. In the practice step, imagine the teammate was an AI assistant: the bugs are the kind they really make.

🧪 Practice

A teammate opened a PR adding applyCoupon(cart, code). It's supposed to:

  • "SAVE10": 10% off the subtotal
  • "FREESHIP": shipping becomes 0
  • unknown codes: throw an Error("Invalid coupon")
  • never modify the cart passed in; return a new object
  • round the total to 2 decimals

It has four bugs. Find and fix them all.

JavaScript
// PR #128: add coupon support
function applyCoupon(cart, code) {
  const result = cart;
  if (code == "SAVE10") {
    result.subtotal = result.subtotal * 0.1;
  } else if (code === "FREESHIP") {
    result.shipping = 0;
  }
  result.total = result.subtotal + result.shipping;
  return result;
}

Output appears here. Press Run or Ctrl/⌘ + Enter.

✅ Check your understanding

  1. How should you phrase review feedback?

Create a free account to track your progress.