Lesson 4 12 min

Debugging Tools

Master essential debugging tools — IDE debuggers, browser DevTools, print debugging, and AI-enhanced workflows for inspecting code state during execution.

🔄 Recall Bridge: In the previous lesson, you learned the 5-step debugging process — reproduce, isolate, identify, fix, verify. Now let’s equip you with the tools that make each step more efficient.

Debugging tools let you observe your program’s state during execution — variable values, call stacks, network requests, and DOM changes. Choosing the right tool for each debugging scenario is a skill that dramatically reduces investigation time.

Tool 1: Print/Log Debugging

The simplest and most universal debugging technique:

Strategic print debugging (not random):

# BAD: Random prints that tell you nothing
print(data)
print("here")
print(result)

# GOOD: Labeled prints with context
print(f"[process_data] Input: {type(data)} len={len(data)}")
print(f"[process_data] After filter: {len(filtered)} items")
print(f"[process_data] Result: {result} (expected: positive)")

AI prompt for print debugging:

I’m debugging this function: [PASTE CODE]. Add strategic print/log statements that will help me trace: (1) What data enters the function, (2) How it changes at each processing step, (3) What decision branches are taken, (4) What comes out. Label each print clearly.

Tool 2: IDE Debugger (Breakpoints)

FeatureWhat It DoesWhen to Use
BreakpointPauses execution at a lineInspect state at a specific point
Conditional breakpointPauses only when condition is true“Stop when i > 100 and value < 0”
Step OverExecute current line, stop at nextFollow execution line by line
Step IntoJump into a function callTrace into deeper function
Step OutRun until current function returnsFinished inspecting, continue
Watch expressionMonitor a value continuouslyTrack computed values

AI prompt for breakpoint strategy:

I’m debugging [DESCRIBE BUG]. Where should I set breakpoints and what conditions should I use? My code: [PASTE].

Tool 3: Browser DevTools

TabDebugsKey Features
ConsoleJavaScript errors, log outputErrors, warnings, interactive JS execution
ElementsHTML/CSS state, event listenersInspect DOM, modify styles live, view listeners
SourcesJavaScript executionBreakpoints, step through code, watch variables
NetworkAPI calls, resource loadingRequest/response data, timing, errors
PerformanceRuntime performanceFrame rate, long tasks, rendering
ApplicationStorage, cookies, service workerslocalStorage, sessionStorage, cookies

Debugging workflow for web apps:

SymptomStart WithThen Check
Button doesn’t workConsole (errors)Elements (event listeners) → Sources (breakpoints)
Page loads slowlyNetwork (waterfall)Performance (long tasks)
Wrong data displayedNetwork (API response)Sources (data processing logic)
Layout brokenElements (computed styles)Console (CSS warnings)
State not updatingSources (breakpoints in state logic)Application (storage)

Tool 4: AI as Debugging Partner

Rubber duck debugging with AI:

I’m stuck on a bug. Let me explain what’s happening and you help me think through it: (1) Expected behavior: [WHAT SHOULD HAPPEN], (2) Actual behavior: [WHAT ACTUALLY HAPPENS], (3) What I’ve checked so far: [LIST], (4) My current hypothesis: [WHAT I THINK IS WRONG]. Poke holes in my hypothesis. What am I missing? What else should I check?

Quick Check: You set a breakpoint in a JavaScript async function. The breakpoint never triggers even though you’re sure the function is called. Why? (Answer: Common causes: (1) The source map doesn’t match the running code — rebuild your project. (2) The function is called but throws before reaching your breakpoint line. Set the breakpoint earlier, or enable “Pause on caught exceptions” in DevTools. (3) You’re debugging the wrong file — if there are multiple copies (bundled and source), the breakpoint might be in the one that’s not executing.)

When to Use Which Tool

SituationBest ToolWhy
Quick value checkPrint statementFastest to add, minimal context switch
Complex state inspectionIDE debuggerSee all variables at once, step through
Web page behaviorBrowser DevToolsInspect DOM, network, JS together
API/network issuesNetwork tab / curlSee exact request and response
Production bugStructured loggingCan’t attach debugger to production
Concurrent/async bugsLogging with timestampsDebuggers alter timing of async code

Key Takeaways

  • Strategic print debugging (labeled, contextual statements) is the most universal tool and often the most practical — works in every environment, leaves a persistent trail, and is faster than a debugger for simple checks; upgrade to a debugger when you need more than 5 prints
  • Browser DevTools panels map to debugging layers: Console for errors, Elements for DOM/events, Sources for code stepping, Network for API calls — using them in order systematically narrows down whether the issue is in JS, DOM, logic, or API
  • AI excels as a rubber duck debugging partner: explain the expected behavior, actual behavior, what you’ve checked, and your current hypothesis — AI pokes holes in your reasoning and suggests what you might be missing

Up Next

In the next lesson, you’ll learn to recognize common bug patterns — the recurring failure modes that cause 80% of bugs — so you can identify them quickly instead of debugging from scratch.

Knowledge Check

1. You're debugging a function with 5 variables changing across 20 iterations of a loop. You add 5 print statements to track each variable. The output is 100 lines of values. You can't find the pattern. What's a better approach?

2. You have a web page where a button click should update a counter display. Clicking does nothing. Where do you start debugging in the browser?

3. A senior developer on your team says: 'I almost never use a debugger — I use print/log statements for 90% of debugging.' Is this a valid approach?

Answer all questions to check

Complete the quiz above first

Related Skills