Skip to content
Tutorials Center
My learning

Topics

Lesson 13 of 36 ยท Console and Sources

Stepping Through Code and Reading the Call Stack

Step over, into and out of functions, read the call stack, scope and watch panes, use async stack traces and blackboxing, with a runnable call-stack simulator.

Once the page is paused at a breakpoint, you decide how to proceed. Do you run the next line, enter the function it calls, or let the current function finish? DevTools gives you stepping controls for this, and a call stack that records how you got here. Mastering both turns debugging from guessing into following a trail.

The stepping controls

At the top of the debugger sidebar (or via keyboard) you have these buttons:

Control Key What it does
Resume F8 Continue running until the next breakpoint or the end.
Step over F10 Run the next line; if it calls a function, run the whole function without entering it.
Step into F11 If the next line calls a function, enter it and pause at its first line.
Step out Shift+F11 Finish the current function and pause in its caller.
Step F9 Like step into, but moves one statement or async hop at a time.
Deactivate breakpoints Ctrl+F8 Ignore all breakpoints without deleting them.

A good routine: step over by default. When a line calls something suspicious, step into it. When you realize the function you entered is fine, step out. Hovering a line number and using Continue to here from the right-click menu runs until that line.

Step into can drop you into library or framework code. Use Step out immediately, or add the library to the Ignore list (blackbox) in settings so stepping skips it. Chrome can also auto-skip such code with the Enable ignore-listing setting.

Reading the call stack

The Call Stack pane lists the functions that are currently running, with the top frame being where execution paused, and each frame below it being the function that called the one above. Click any frame to view its code and its variables in Scope; you can go back up the chain without running anything.

The stack answers "how did we get here?", and it is also what you see in error messages. A shape like:

Text
validate           form.js:42
handleSubmit       form.js:18
(anonymous)        main.js:7

means (anonymous) in main.js called handleSubmit, which called validate. A bug appearing in validate may really be caused by what handleSubmit passed in, so click the lower frame and check its variables.

Async code complicates this: after an await or inside a promise callback, the original caller is gone from the real stack. Chrome keeps an async stack trace: frames labelled with the word async (for example async fetchUser) link back to the code that started the work. Turn on async stack traces in the Call Stack pane if they are off; they are on by default in current Chrome.

Scope and Watch

The Scope pane groups variables into:

  • Local: variables of the current function (plus this, arguments).
  • Closure: variables from enclosing functions that the current one uses.
  • Script/Global: top-level let and const declarations and window properties.
  • Block: variables from the current block ({}).

Values are live: expand objects, and double-click a value to edit it, then resume to see the effect. This is one of the fastest ways to test a hypothesis ("what if count were 0?") without changing source.

The Watch pane takes expressions, such as items.length or user?.name, and re-evaluates them at every pause. Watch expressions that throw show an error rather than stopping the debugger. Click the + to add one.

Stand-in: a stepping debugger

You cannot attach a real debugger on this site, but you can model one. The program below runs a tiny instruction list, tracks a call stack, and supports step over, step into and step out. It teaches how the controls differ; it is not Chrome's engine.

JS Stand-in: step over, step into, step out

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Read the output from top to bottom: after the first step over the program has only moved to the line that calls checkout; the first step into enters it (the bracketed path grows), the second moves to the next call, and step out finishes everything and returns to main. The bracketed path is a model of the Call Stack pane.

Stand-in: building a stack trace

Errors carry a stack trace string, which is the same information as the Call Stack pane at the moment the error was created. You can read it in code through new Error().stack. This stand-in parses a trace into frames. (The format varies slightly between browsers; here we assume the Chrome style.)

JS Stand-in: parsing a stack trace

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Blackboxing and Ignore list

Frameworks add many frames that hide your own. In Settings, Ignore List, add patterns (for example node_modules or a library file) and Chrome will:

  • skip those frames when you step,
  • hide or collapse them in the call stack,
  • avoid pausing inside them on exceptions.

You can also right-click a file in the Sources panel and choose Add script to ignore list.

A debugging recipe

  1. Reproduce the bug, and find a starting point: an error line, an XHR breakpoint or an event breakpoint.
  2. Pause, read Scope, and compare each value with what you expected.
  3. Click through the Call Stack to find the first frame whose variables are wrong.
  4. Step forward in that function until the wrong value appears.
  5. Test a fix by editing a value or by editing the file in the editor (Ctrl+S in a workspace or override), then resume.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does Step over (F10) do when the next line calls a function?

    Step over executes the call completely and stops at the following line in the same function.
  2. 2. In a call stack, where is the function that was running when the pause happened?

    The top frame is the current function; frames below it are its callers.
  3. 3. What is an async stack trace?

    It reconstructs the logical chain of calls across asynchronous boundaries.
  4. 4. How do you stop stepping from landing inside a framework's code?

    Ignore-listed scripts are skipped when stepping and collapsed in the call stack.

Summary

  • Step over runs a line, step into enters a call, step out finishes the function, resume continues.
  • The call stack shows how you got here; click frames to see their variables.
  • Scope shows live variables you can edit; Watch re-evaluates expressions at every pause.
  • Use async stack traces and the Ignore list to keep modern, framework-heavy code readable.

Next: Snippets, Overrides, Workspaces and Source Maps