debugger

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

語法

debugger;

示例

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

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

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

Paused at a debugger statement.

規範

規範 狀態 註解
ECMAScript Latest Draft (ECMA-262)
The definition of 'Debugger statement' in that specification.
Draft
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Debugger statement' in that specification.
Standard
ECMAScript 5.1 (ECMA-262)
The definition of 'Debugger statement' in that specification.
Standard 初期定義
ECMAScript 3rd Edition (ECMA-262)
The definition of 'Debugger statement' in that specification.
Standard
ECMAScript 1st Edition (ECMA-262)
The definition of 'Debugger statement' in that specification.
Standard 只作為保留字而提到

瀏覽器相容性

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
debuggerChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes

Legend

Full support  
Full support

參見