Breakpoints in DevTools
Breakpoints in DevTools in Modern JavaScript
While console.log() is commonly used for quick debugging, enterprise development requires interactive debugging using browser Developer Tools. Setting breakpoints pauses JavaScript execution, enabling you to inspect local scope variables, evaluate expressions in the console, and step through code execution line by line.
1. Opening DevTools and the Sources Tab
In Google Chrome, Microsoft Edge, or Firefox:
- Press
F12orCtrl + Shift + I(Windows/Linux) orCmd + Option + I(Mac). - Navigate to the Sources (or Debugger in Firefox) tab.
- Press
Ctrl + Pto quickly find and open any source file.
2. Types of Breakpoints
1. Line-of-Code Breakpoint
Click directly on any line number in the source editor (a blue/orange marker appears). Execution pauses right before that line executes.
2. The debugger; Statement
Place the debugger; statement directly in your source code. When DevTools is open, execution automatically pauses at that statement:
3. Conditional Breakpoints
Right-click a line number and choose Add conditional breakpoint.... Enter an expression (e.g. userId === 99 or price > 500). Execution will pause only when that expression evaluates to true!
4. DOM Mutation Breakpoints
Right-click any HTML element in the Elements panel -> Break on ->:
- Subtree modifications: Pauses when child nodes are added or removed.
- Attribute modifications: Pauses when class or style attributes change.
- Node removal: Pauses when the element is deleted.
3. Stepping Controls
Once paused, use the debugging controls:
| Button | Key | Action | Description |
|---|---|---|---|
| Resume | F8 | Continue execution | Runs until the next breakpoint or script completion |
| Step Over | F10 | Next line | Executes current line without stepping into function calls |
| Step Into | F11 | Dive inside | Steps into the function invoked on current line |
| Step Out | Shift + F11 | Jump out | Finishes current function and returns to caller |
4. Scope and Watch Panels
While paused at a breakpoint:
- Scope Panel: Displays all variables currently in scope (
Local,Closure,Global) and their real-time memory values. - Watch Expressions: Click
+to monitor custom expressions (e.g.,cart.items.length * taxRate) that re-evaluate at every step. - Interactive Console: The console evaluates expressions in the context of the paused stack frame.
Practice Quiz
Network Tab for API Calls
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
| Previous Lesson | Next Lesson |
|---|---|
| Using console methods | Network Tab for API Calls |
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.