--- title: debugger slug: Web/JavaScript/Reference/Statements/debugger translation_of: Web/JavaScript/Reference/Statements/debugger --- <div>{{jsSidebar("Statements")}}</div> <p><strong>debugger 的宣告</strong>會執行可用的除錯功能,例如設定斷點。如果沒有可用的除錯功能,這個宣告沒有任何作用。</p> <h2 id="語法">語法</h2> <pre class="syntaxbox"><code>debugger;</code></pre> <h2 id="示例">示例</h2> <p>以下示例示範了插入 debugger 宣告的程式碼,它會在函式被呼叫、而且有除錯器的時候執行除錯器。</p> <pre class="brush:js">function potentiallyBuggyCode() { debugger; // 執行並驗證一些潛在的問題、或是單步執行之類的。 }</pre> <p>呼叫除錯器時,程式會在 debugger 宣告處暫停執行。它有點像是程式碼的斷點。</p> <p><a href="https://mdn.mozillademos.org/files/6963/Screen Shot 2014-02-07 at 9.14.35 AM.png"><img alt="Paused at a debugger statement." src="https://mdn.mozillademos.org/files/6963/Screen%20Shot%202014-02-07%20at%209.14.35%20AM.png"></a></p> <h2 id="規範">規範</h2> <table class="standard-table"> <tbody> <tr> <th scope="col">規範</th> <th scope="col">狀態</th> <th scope="col">註解</th> </tr> <tr> <td>{{SpecName('ESDraft', '#sec-debugger-statement', 'Debugger statement')}}</td> <td>{{Spec2('ESDraft')}}</td> <td></td> </tr> <tr> <td>{{SpecName('ES6', '#sec-debugger-statement', 'Debugger statement')}}</td> <td>{{Spec2('ES6')}}</td> <td></td> </tr> <tr> <td>{{SpecName('ES5.1', '#sec-12.15', 'Debugger statement')}}</td> <td>{{Spec2('ES5.1')}}</td> <td>初期定義</td> </tr> <tr> <td>{{SpecName('ES3', '#sec-7.5.3', 'Debugger statement')}}</td> <td>{{Spec2('ES3')}}</td> <td></td> </tr> <tr> <td>{{SpecName('ES1', '#sec-7.4.3', 'Debugger statement')}}</td> <td>{{Spec2('ES1')}}</td> <td>只作為保留字而提到</td> </tr> </tbody> </table> <h2 id="瀏覽器相容性">瀏覽器相容性</h2> <p>{{Compat("javascript.statements.debugger")}}</p> <h2 id="參見">參見</h2> <ul> <li><a href="/zh-TW/docs/Debugging_JavaScript">JavaScript 除錯</a></li> <li><a href="/zh-TW/docs/Tools/Debugger">Firefox 開發工具的的除錯器</a></li> </ul>