Skip to content

Code Review Basics

Reviewing pull requests effectively — giving constructive feedback and using review checklists.

What you'll learn

  • How to review a pull request systematically
  • Giving constructive, kind feedback
  • What to look for: logic, security, style, tests
  • Using review tools and inline comments on GitHub

Concept

Why Code Review Matters

Code review is the practice of having another developer examine your code before it merges. It catches bugs, improves code quality, shares knowledge across the team, and ensures more than one person understands each part of the codebase.

A good review process is the single most effective quality practice in software development. Studies show it catches 60-90% of defects before they reach production.

The Review Checklist

When reviewing a PR, check these areas:

1. Correctness

  • Does the code do what the PR description says?
  • Are edge cases handled (null, empty, negative, overflow)?
  • Are error paths covered?
  • Does the logic match the requirements?

2. Security

  • Are user inputs validated and sanitized?
  • Are secrets, keys, and passwords kept out of the code?
  • Are SQL queries parameterized (no injection)?
  • Are authentication and authorization checks present?

3. Tests

  • Are there tests for the new code?
  • Do the tests cover edge cases, not just the happy path?
  • Do the tests actually assert meaningful behavior?
  • Will the tests pass in CI?

4. Style and Readability

  • Does the code follow the project's style guide?
  • Are names clear and descriptive?
  • Is complex logic explained with comments?
  • Is the code DRY (no unnecessary duplication)?

5. Performance

  • Are there obvious performance issues (N+1 queries, unnecessary loops)?
  • Are database queries efficient?
  • Are large allocations or copies avoidable?

6. Design

  • Does this change fit the existing architecture?
  • Are responsibilities in the right modules?
  • Is the public API well-designed?

How to Review on GitHub

  1. Open the PR and read the description
  2. Check out the branch locally for complex reviews:
   git fetch origin
   git checkout feature-branch
   # run the code, run the tests
  1. Review the diff file by file on GitHub
  2. Leave inline comments by hovering over a line and clicking the + icon
  3. Suggest changes with the suggestion button (creates a code suggestion the author can apply with one click)
  4. Submit your review — choose "Comment", "Approve", or "Request changes"

Giving Constructive Feedback

Good review comments are kind, specific, and actionable:

  • ✅ "This loop could be replaced with a filter() call for clarity. What do you think?"
  • ✅ "I think there's an edge case when users is empty — the reduce would throw. Could we add a guard?"
  • ✅ "Nice use of the strategy pattern here! One suggestion: the function name could be more specific, like calculateDiscount instead of calculate."

Bad review comments are vague, harsh, or unhelpful:

  • ❌ "This is wrong."
  • ❌ "Why would you write it this way?"
  • ❌ "Bad code."

The Review Etiquette

  • Be kind — there is a human on the other side. Critique the code, not the person.
  • Be specific — point to exact lines and explain the issue.
  • Ask questions — "Could this be null here?" is better than "This will crash."
  • Praise good work — highlight things done well, not just problems.
  • Respond to feedback — if you are the author, address every comment, even if just to acknowledge it.
  • Don't block on style nits — use "nit:" prefix for minor style suggestions that should not block the merge.

Reviewing Your Own Code First

Before requesting review, self-review your PR:

  • Read through the diff on GitHub
  • Check that you have not left debug code (console.log, print statements)
  • Verify the CI checks pass
  • Make sure the description is complete

Self-review catches many simple issues before they reach your reviewer.

Example

              # --- Check out a PR locally for thorough review ---
# Method 1: fetch and checkout the branch
git fetch origin pull/42/head:pr-42
git checkout pr-42

# Method 2: using GitHub CLI
gh pr checkout 42

# Run the code and tests locally
npm install
npm test
npm run lint

# --- Review workflow on GitHub ---
# 1. Read the PR description
# 2. Review the diff file by file
# 3. Leave inline comments on specific lines
# 4. Use the suggestion feature:
#    - Click the "+" icon next to a line
#    - Write your suggestion in a code block
#    - The author can apply it with one click

# --- Submit the review ---
gh pr review 42 --approve --body "Great work! Just a few nits inline."
gh pr review 42 --request-changes --body "Please address the security concern about SQL injection."
gh pr review 42 --comment --body "Looks good overall, leaving some questions inline."

# --- Apply a suggestion from a reviewer (as the PR author) ---
# On GitHub, click "Apply suggestion" on each suggestion comment
# Then push the changes:
git push

# --- View review status ---
gh pr view 42 --comments
gh pr checks 42  # see CI status

# --- Keep the PR branch updated with main ---
git fetch origin
git rebase origin/main
git push --force-with-lease
            

Shows checking out a PR locally for thorough review, running tests, submitting reviews via the GitHub CLI (approve, request changes, comment), applying reviewer suggestions, and keeping the PR branch updated. The gh pr checkout command is the fastest way to review locally.

Try it

  • Code Diff

    Compare code versions — the core of reviewing a PR diff.

  • CI/CD YAML Generator

    Generate CI checks that run automatically on PRs for review.

Common mistakes

The mistake

Rubber-stamping PRs without actually reading the code

The fix

A review is only valuable if you actually read the code. Read the diff, understand the changes, check edge cases and tests. If the PR is too large to review thoroughly, ask the author to split it. A 'LGTM' without reading helps no one.

The mistake

Being harsh or personal in review comments

The fix

Review the code, not the person. Use phrases like 'This could be simplified by...' instead of 'This is bad'. Ask questions rather than making demands. Remember there is a colleague on the other side. Kind reviews build trust; harsh reviews create resentment and slow down the team.

Related Cheatsheets

Practice Code Review Basics

1 exercise

Practice Code Review Basics

Look up unfamiliar terms

A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.

View glossary

Build real projects

Apply what you learned by building guided projects with starter code and solutions.

View projects

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors