debugger

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

debugger 的宣告會執行可用的除錯功能,例如設定斷點。如果沒有可用的除錯功能,這個宣告沒有任何作用。

語法

debugger;

示例

以下示例示範了插入 debugger 宣告的程式碼,它會在函式被呼叫、而且有除錯器的時候執行除錯器。

js
function potentiallyBuggyCode() {
  debugger;
  // 執行並驗證一些潛在的問題、或是單步執行之類的。
}

呼叫除錯器時,程式會在 debugger 宣告處暫停執行。它有點像是程式碼的斷點。

Paused at a debugger statement.

規範

Specification
ECMAScript Language Specification
# sec-debugger-statement

瀏覽器相容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
debugger

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

參見