Movatterモバイル変換


[0]ホーム

URL:


Menu
×
See More 
Sign In
+1 Get Certified Upgrade Teachers Spaces Bootcamps Get Certified Upgrade Teachers Spaces Bootcamps
   ❮     
     ❯   

Basic JavaScript

JS TutorialJS SyntaxJS VariablesJS OperatorsJS If ConditionsJS LoopsJS StringsJS NumbersJS FunctionsJS ObjectsJS ScopeJS DatesJS Temporal DatesJS ArraysJS SetsJS MapsJS IterationsJS MathJS RegExpJS DestructuringJS Data TypesJS ErrorsJS DebuggingJS ConventionsJS ReferencesJS 2026JS Versions

JS HTML

JS HTML DOMJS EventsJS ProjectsNew

JS Advanced

JS FunctionsJS ObjectsJS ClassesJS AsynchronousJS ModulesJS Meta & ProxyJS Typed ArraysJS DOM NavigationJS WindowsJS Web APIsJS AJAXJS JSONJS jQueryJS GraphicsJS ExamplesJS 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 withF12 and go to theSources tab.

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

Reload the page to trigger the breakpoint.

Use theplay button to run your code line by line.


The debugger Keyword

Thedebugger 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 theconsole.log() method in ourJavaScript 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 manyconsole.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 ourterms of use,cookies andprivacy policy.

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

-->
[8]ページ先頭

©2009-2026 Movatter.jp