skip to content

Sources Panel Breakpoints

Conditional breakpoints, logpoints, DOM and XHR breakpoints, stepping and async stack traces. Interviewers ask how you would find a bug without scattering console.log through the code.

on this pageshow

explore

questions

6

In Chrome DevTools, how do you pause a script at a chosen line, then step over, into and out of its calls?

level: juniorimportance: must knowfreq 58%

answer

  1. start in the Sources panel
  2. click the line number gutter
  3. pauses before the line runs
  4. over, into and out differ at calls
  5. F10, F11, Shift+F11, then F8

basics

~20 s

Open the Sources panel, click a line number to set a breakpoint, and trigger the code. Execution pauses before that line; Step over runs a call whole, Step into enters it, and Step out finishes the current function.

solid answer

~50 s

I open the file in the **Sources** panel and click the line number, which sets a line-of-code breakpoint, then trigger the code. DevTools pauses *before* that line runs, so an assignment on it has not happened yet. From there I choose the step by what the next call means to the bug. **Step over** (`F10`) runs the call whole and stops on the next statement, unless a breakpoint inside it fires first. **Step into** (`F11`) goes inside the call, and **Step out** (`Shift+F11`) finishes the current function and stops back in its caller. **Resume script execution** (`F8`) runs on to the next breakpoint. If a long stretch is irrelevant, right-clicking a line and choosing **Continue to here** saves the stepping. A `debugger;` statement pauses just like a line breakpoint but lives in the source, so it has to come out before it ships.

code

javascript · 3 lines
javascript
console.log('a');
debugger; // pauses here while DevTools is open, does nothing otherwise
console.log('b');

go deeper

for a junior

Recall the path: Sources panel, click the line number, trigger the code. Then say what each of the three steps does at a function call, and that the pause comes before the line runs.

for a middle

Explain why Step over still executes the call and can still stop inside it. Mention Continue to here and the Breakpoints pane, so stepping does not sound like your only way of moving around.

for a senior

Show that stepping is the last mile, not the method. Say how you reach the right line first, and when a plain line breakpoint is the wrong tool because you do not yet know where the code lives.

for a principal

Treat this as a baseline for the team rather than a debate. The angle worth raising is whether engineers actually use the debugger or default to logging, since that habit shapes how long a production diagnosis takes.

## What a breakpoint does A **breakpoint** tells the browser's debugger to stop running JavaScript at a chosen place, so you can look at the program while it is frozen instead of guessing from its output. The **Sources** panel is where Chrome DevTools shows the page's scripts and the controls for a pause. A **line-of-code breakpoint** is the simplest kind: it stops at one line, and DevTools pauses *before* that line runs. If the line is `const discount = getDiscount(cart);`, then `discount` has not been assigned when you stop there. Breakpoints fire only while DevTools is open. A visitor without DevTools runs the same code at full speed, because the breakpoint lives in your DevTools session and not in the file the server sent. ## Setting one 1. Open DevTools and select the **Sources** panel. 2. Open the file from the tree on the left of the panel. 3. Click the line number. A marker appears in the gutter and the line is listed in the **Breakpoints** pane. 4. Trigger the code, for example by clicking the button that runs it. 5. When execution stops, the line is highlighted and the **Call Stack** and **Scope** panes fill in. Before a pause, both of them just say `Not paused`. ## The stepping controls | Control | Key | What it does | Reach for it when | |---|---|---|---| | **Resume script execution** | `F8` | Runs until the next breakpoint, if any | You have finished looking here | | **Step over** | `F10` | Runs the next call whole, then pauses on the next statement | The call is not related to the problem | | **Step into** | `F11` | Enters the next call and pauses on its first statement | The call may hold the bug | | **Step out** | `Shift+F11` | Runs the rest of the current function and pauses in its caller | You no longer care about this function | | **Step** | `F9` | Moves to the next statement in synchronous order | You want to walk the code as it runs right now | These also have second bindings, such as `Ctrl+'` or `Cmd+'` for Step over. Most people learn the function keys and stop there. ## A worked trace ```js function updateTotal(cart) { const discount = getDiscount(cart); // A render(cart.total - discount); // D } function getDiscount(cart) { const rate = cart.coupon ? 0.1 : 0; // B return cart.total * rate; // C } ``` - Paused on `A`, **Step over** runs all of `getDiscount`, including `B` and `C`, and then pauses on `D`. - Paused on `A`, **Step into** pauses on `B`, inside the called function. - Paused on `B`, **Step out** runs `C`, returns, and pauses back in `updateTotal`. The point people miss is that **Step over does not skip execution**. The function really ran, with all its side effects; you only declined to stop inside it. If a breakpoint sits inside that call, it still fires, and you stop there instead of on the next statement. ## Other ways to pause and move - **The `debugger;` statement** has the same effect as a line-of-code breakpoint, but it is written into the source. It is handy when you are editing the code anyway, and it does nothing when no debugger is attached. The cost is a rebuild to add it and another to remove it. - **Continue to here** appears when you right-click a line while paused. DevTools runs up to that line and pauses, without leaving a permanent breakpoint behind. - **The Breakpoints pane** lists every line-of-code breakpoint, grouped by file. A checkbox disables one without losing it, and right-clicking offers removal or **Reveal location**. - **Deactivate breakpoints** (`Ctrl+F8` or `Cmd+F8`) is a single toggle for all of them at once, for when you need the page to run freely for a while and want your breakpoints back later. ## Mistakes worth avoiding - Expecting the value assigned on the paused line to be visible already. Step once and look again. - Pressing Step over hundreds of times through a loop. A conditional breakpoint gets you to the right iteration directly. - Staying lost inside a library after a wrong Step into. **Step out** brings you back to your own code in one key press. - Committing a stray `debugger;`. Visitors never notice it, which is why it slips through, but it stops every colleague who has DevTools open.

  • What is the difference between F9 and F11 in the Chrome DevTools Sources panel?
    Both enter an ordinary synchronous call. `F11`, **Step into next function call**, also follows a callback the line schedules, such as a `setTimeout` callback, and pauses at its start. `F9`, **Step**, does not make that jump: it moves to the next statement in synchronous order, so you stay with the code that is running right now.
  • Why does Step over sometimes stop inside the function you meant to skip?
    Step over only declines to stop for stepping; any breakpoint inside the call still fires. A line-of-code breakpoint, a conditional breakpoint whose condition is true or a `debugger;` statement inside that function will stop you there first. Disable that breakpoint, or use **Deactivate breakpoints**, if you want the call to run through.
  • When is a debugger statement a better choice than clicking a line number?
    When you are already editing the code, a `debugger;` statement travels with the change, can sit inside your own `if`, and does not depend on a line number that a rebuild might move. Its cost is a rebuild each way and the risk of committing it. For anything already deployed, a DevTools breakpoint needs no source change at all.

  • A breakpoint pauses after its line has run, so the assignment on it is already done.
  • Step over skips the call, so the function's code does not execute.
  • Step out returns to the caller without running the rest of the function.
  • Inspecting a value requires adding console.log calls and reloading the page.
  • A debugger statement left in the code freezes every visitor's browser in production.
open as a page

In Chrome DevTools, how do you find the code behind a checkout button that sometimes does nothing, in a large bundled application you did not write?

level: seniorimportance: must knowfreq 55%

basics

~20 s

Do not read the bundle: make the symptom pause you. Use an Event Listener Breakpoint on click, an XHR/fetch breakpoint on the request URL, a DOM change breakpoint on the button and Pause on caught exceptions, then read the Call Stack.

open as a page

In Chrome DevTools, a bug hits only the fifth item of a list: would you use a conditional breakpoint or a logpoint, and why?

level: middleimportance: should knowfreq 52%

basics

~20 s

Use a conditional breakpoint to pause only when an expression such as index === 4 is true. Use a logpoint to print values on every hit without pausing, when you need the sequence or a pause would hide the bug.

open as a page

In Chrome DevTools, what do Pause on uncaught exceptions and Pause on caught exceptions each stop on, and when do you need the second?

level: middleimportance: should knowfreq 42%

basics

~20 s

Pause on uncaught exceptions stops on a throw no handler will catch; Pause on caught exceptions stops on a throw a handler will absorb. You need the second when something swallows an error and the feature fails silently.

open as a page

While paused in Chrome DevTools, how do you test a theory about a wrong value without reloading the page and reproducing the bug again?

level: middleimportance: should knowfreq 38%

basics

~20 s

Edit the value in the Scope pane, track derived expressions in Watch, run code in the Console against the selected frame, then use Restart frame to run the function again. Restarting does not undo what the function already changed.

open as a page

In Chrome DevTools, paused in a promise callback holding a wrong total, how do you find what scheduled it and step across that async hop?

level: seniorimportance: nice to knowfreq 33%

basics

~20 s

The Call Stack pane adds async sections below the running frames, showing the code that scheduled this callback; those frames give locations, not live variables. Step into (F11) follows a callback the current line schedules, while Step (F9) stays with synchronous code.

open as a page