This guide shows how to debug JavaScript Chrome DevTools sessions step by step: open the Sources panel, set a breakpoint, and let the code stop so you can inspect variables, the call stack, and the exact line that runs. That pause is the whole skill. Console logs can tell you what happened after the fact, but a breakpoint shows you the live state at the moment things go wrong, and that is usually where the bug lives.
Most developers learn DevTools in pieces: a console.log here, an Elements panel tweak there. The debugger stays untouched because it looks heavy. It is not. The core loop is short: reproduce the bug, pause the code, read the state, step forward, fix the cause.
Open DevTools and Reach the Sources Panel
Press F12, or Ctrl+Shift+I on Windows and Linux, or Cmd+Option+I on a Mac. Right-click any element and choose Inspect to open DevTools with the Elements panel focused. The Sources panel is where debugging happens. It shows your files in a tree on the left, the code in the middle, and the debugging tools on the right: scope, watch expressions, the call stack, and breakpoints.
On a production site the code is often minified into one long line. Click the curly braces icon at the bottom of the code pane to pretty-print it back into readable code. Source maps make this even better: when the site ships them, DevTools shows your original files and lets you debug those directly, even though the browser runs the built bundle.
The Console panel sits next to Sources. You can run code against the live page there, and when the debugger is paused you can type expressions in the console and they run in the paused scope. That combination is powerful: pause at a line, then ask the console what a variable holds or what a function returns.
Set Your First Breakpoint
Click a line number in Sources to set a breakpoint, shown as a blue marker. Reload the page or trigger the action, and the code stops on that line before it runs. The Scope panel shows local variables and the Call Stack panel shows how the code got there.
There are four ways to pause code, and each fits a different situation:
- Line breakpoint. Click a line number. The code stops there every time it runs. Use it when you know the rough location of the bug.
- Conditional breakpoint. Right-click a line number, choose Add conditional breakpoint, and type a condition such as
user.id === 42. The code only stops when the condition is true. This is the tool for bugs that happen once in a hundred loop rounds. - Logpoint. Right-click a line number and choose Add logpoint, then type an expression in braces, like
{user.name}. It prints to the console without stopping the code and without editing the file. - Event listener breakpoint. In the right-hand panel, open Event Listener Breakpoints and tick an event such as click, keydown, or submit. The debugger pauses inside the handler for that event. Use it when you do not know which handler runs.
Step Through Code Without Getting Lost
Once the code is paused, four buttons move it forward:
| Button | Shortcut | What it does |
|---|---|---|
| Resume | F8 | Runs until the next breakpoint |
| Step over | F10 | Runs the current line, stays in this function |
| Step into | F11 | Enters the function on the current line |
| Step out | Shift+F11 | Finishes the current function, returns to the caller |
Step over is the default move. It runs one line and stays at the same level, which keeps you moving through the function you care about. Step into is for the moment a function call looks wrong: press it and you land inside the called function, where you can watch its own variables. Step out is the escape hatch when you stepped into a library function by accident.
While paused, hover over any variable in the code pane to see its current value. That beats adding logs for a quick check. The Scope panel lists every variable in the local, closure, and global scopes, and the Watch panel lets you pin expressions that update as you step.
Read the Call Stack to Find the Real Caller
When a function runs at the wrong time or with the wrong data, the question is rarely what the function does. It is who called it. The Call Stack panel answers that: it lists each function on the stack, from the paused function at the top back to the first call at the bottom. Click any frame to jump to that call site and see its variables.
This is how you trace a bad value to its source. A variable is wrong inside a helper. Click the frame below it and the value is wrong there too. Keep going down until you reach the frame where the value first goes wrong, and you have found the line that needs fixing.
Async code adds frames that look confusing at first. DevTools marks async boundaries in the stack, so you can see that a callback came from a timer or a fetch. A guide to how the JavaScript event loop actually works explains the queue and microtask rules behind those frames, which helps when a callback runs in an order you did not expect.
How to Debug JavaScript Chrome DevTools Sessions With the Console
The console is more than a place to print values. It is a live REPL attached to the page. When the debugger is paused, anything you type runs in the paused scope, so you can call functions, change variables, and test a fix before editing the file. Type a variable name to see its value. Call a function with different arguments to see if it behaves.
A few console helpers are built for debugging:
// Print an object as a table, easy to scan
console.table(users);
// Print a value only when a condition holds
console.assert(user.age >= 0, "Negative age", user);
// Print the stack at this exact point
console.trace("reached here");
console.table is the one developers underuse most. A list of objects as rows is far easier to scan than ten collapsed objects. And $0 in the console refers to the element currently selected in the Elements panel, while $_ holds the result of the last expression.
Debug Network, DOM, and Performance Problems
Not every JavaScript bug lives in your code. Sometimes the data never arrives, the DOM changes under you, or the page is slow. DevTools has a panel for each of those.
When the data is wrong, open the Network panel, reload, and click the request that matters. The Payload tab shows what was sent and the Response tab shows what came back. If the response is wrong, the bug is on the server or in the request. If the response is right and the page is still wrong, the bug is in your rendering code.
When the DOM changes on its own, right-click an element in the Elements panel and choose Break on, then subtree modifications. The debugger pauses the moment any script changes that element.
When the page is slow, open the Performance panel, record, reproduce the slow action, and stop. The flame chart shows which functions took the time, and long tasks stand out as wide blocks. Fix the widest block first. Knowing how closures hold state between calls helps here too, because a handler that closes over a large object can keep memory alive and slow the page down over time.
Common Debugging Mistakes That Waste Time
The other common mistake is adding logs and never removing them. Logs left in production code slow the page and leak data into the console. Use logpoints instead of temporary console.log calls when you can, and delete the logs you did add before committing. A clean bug report helps the next step too: this template for bug reports developers actually read covers what to include so a fix can be verified instead of guessed at.
Frequently Asked Questions
Can I debug JavaScript in Chrome DevTools on a live production site?
Yes, if you can open DevTools on the page. You can set breakpoints, inspect variables, and run expressions in the console. You cannot save changes back to the server from DevTools, so use it to find the bug, then fix the source and deploy.
Why does the debugger keep pausing in library code?
You stepped into a function from a library or framework, or an exception fired inside one. Add the library files to the ignore list in DevTools settings so the debugger skips them.
Debugging is a loop, not a talent. Reproduce the bug, pause the code, read the state, and follow the stack to the first wrong value. The more often you run that loop in DevTools instead of guessing from logs, the shorter the loop gets.