Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST

Basic JavaScript

JS Tutorial JS Syntax JS Variables JS Operators JS If Conditions JS Loops JS Strings JS Numbers JS Functions JS Objects JS Scope JS Dates JS Temporal Dates JS Arrays JS Sets JS Maps JS Iterations JS Math JS RegExp JS Data Types JS Errors JS Debugging JS Conventions JS References JS ECMAScript 2026 JS Versions

JS HTML

JS HTML DOM JS Events JS Projects

JS Advanced

JS Functions JS Objects JS Classes JS Asynchronous JS Modules JS Meta & Proxy JS Typed Arrays JS DOM Navigation JS Windows JS Web APIs JS AJAX JS JSON JS jQuery JS Graphics JS Examples JS Reference


JavaScript Debugging Breakpoints

Breakpoints, Watch, Scope

Breakpoints let you pause JavaScript and inspect what is really happening.

This is the most powerful debugging technique after using the console.

What Is a Breakpoint

A breakpoint pauses code execution on a specific line.

When the code stops, you can inspect variables and step through the code line by line.

Breakpoints are set inside the browser developer tools.

Note

You do not guess values when using breakpoints.

You see them.


Setting a Breakpoint

In the debugger window, you can set breakpoints in the JavaScript code.

At each breakpoint, JavaScript will stop executing, and let you examine JavaScript values.

After examining values, you can resume the execution of code (typically with a play button).

Example

function add(a, b) {
  let result = a + b;
  return result;
}

document.getElementById("demo").innerHTML = add(10, 5);
document.getElementById("demo").innerHTML = add(10, 50);
document.getElementById("demo").innerHTML = add(10, 500);
document.getElementById("demo").innerHTML = add(10, 5000);
Try it Yourself »

Open the browser developer tools with F12 and go to the Sources tab.

Click on the line numbers in your script to add breakpoints.

Reload the page to trigger the breakpoint.

Use the play button to run your code line by line.


The debugger Keyword

The debugger keyword stops the execution of JavaScript, and calls (if available) the debugging function.

This has the same function as setting a breakpoint in the debugger.

If no debugging is available, the debugger statement has no effect.

With the debugger turned on, this code will stop executing before it executes the third line.

Example

let x = 15 * 5;
debugger;
document.getElementById("demo").innerHTML = x;
Try it Yourself »

Learn More

Read more about the console.log() method in our JavaScript Console Reference.


Stepping Through Code

When execution is paused, you can control how the code runs.

  • Step Over runs the next line.
  • Step Into enters a function.
  • Step Out exits the current function.

Step slowly and watch how values change.


The Scope Panel

The Scope panel shows which variables are available at the current line.

It helps you understand where variables live.

  • Local variables exist inside a function.
  • Global variables exist everywhere.

Example:

let x = 10;

function test() {
  let y = 5;
  console.log(x + y);
}

test();

At the breakpoint, y exists only inside the function.


Watching Variables

The Watch panel lets you track variable values live.

This is useful when values change many times.

Add a variable name to the Watch panel.

The value updates automatically as you step through the code.

Watch variables instead of adding many console.log() calls.


Common Beginner Mistakes

Beginners often forget to reload the page after adding a breakpoint.

Breakpoints inside loops can trigger many times.

If execution stops repeatedly, disable the breakpoint temporarily.


When to Use Breakpoints

  • When values change unexpectedly.
  • When code runs but produces wrong results.
  • When debugging complex logic.

Next: Common Errors Explained

Next page explains the most common JavaScript error messages.

You will learn what they mean and how to fix them.


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

-->