English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
程序或脚本中的错误称为bug。
调试(Debugging)是测试,发现和减少计算机程序中的错误(bug)的过程。
所有主流浏览器都具有内置的JavaScript调试器。
可以打开和关闭内置调试器,从而将错误报告给用户。
使用调试器,您可以在某些断点(可以停止执行代码的位置)处暂停代码。
一旦执行停止,您可以检查脚本的状态及其变量,以确定是否有问题。
您还可以观察变量值的变化过程。
如果您的浏览器支持调试,则可以用来console.log()在调试器窗口中显示JavaScript值:
let x = 50; let y = 20; let z = x + y; console.log(z);Test and see‹/›
要访问Web浏览器的控制台,请先按F12键盘上的键,然后单击“控制台”选项卡。
debugger关键字调用的任何可用的调试功能性,如设置一个断点。
If there is no available debugging feature, this statement is invalid.
The following example shows the code where the debugger insertion statement is used to call the debugger:
var a = 50 + 20; debugger; document.getElementById("output").innerHTML = a;Test and see‹/›
When the debugger is called, the execution of the debugger statement will pause. This is like a breakpoint in the script source.
Generally, you use the activated browserF12From Debugging, then select 'Console' from the Debugger menu.
Otherwise, please follow the steps below:
Open the Browser
From Menu, select 'More Tools'
From Tools, select 'Developer Tools'
Finally, select Console
Open the Browser
From the menu, select 'Web Developers'
Finally, select 'Web Console'
Open the Browser
From the menu, select 'Developer Tools'
Finally, select 'Console'
Open the Browser
From the menu, select 'Developer'
From 'Developers', select 'Developer Tools'
Finally, select 'Console'
Go to Safari, Preferences, Advanced
Check 'Enable Developer Menu in Menu Bar'
When the new option 'Developer' appears in the menu:
Select 'Show Error Console'