JavaScript debugging and javascript debugging
When writing JavaScript, it would be very painful if no debugging tool is available.
JavaScript debugging
It is difficult to write JavaScript programs without debugging tools.
Your code may contain syntax errors and logic errors. If no debugging tool is available, these errors are hard to be found.
Generally, if an error occurs in JavaScript, there is no prompt, So that you cannot find the location of the code error.
|
Generally, errors occur when writing a new JavaScript code. |
JavaScript debugging tool
Finding an error in the program code is called code debugging.
Debugging is difficult, but fortunately many browsers have built-in debugging tools.
Built-in debugging tools can be started or disabled, and severe error messages will be sent to users.
With the debugging tool, we can set breakpoints (where the code stops executing) and detect variables during code execution.
To enable the debugging tool in the browser, press the F12 key and select "Console" from the debugging menu ".
Console. log () method
If the browser supports debugging, you can use the console. log () method to print the JavaScript value in the debugging window:
Instance
My First Web Page
<Script>
A = 5;
B = 6;
C = a + B;
Console. log (c );
</Script>
Set breakpoints
In the debugging window, you can set the breakpoint of JavaScript code.
At each breakpoint, JavaScript code execution is stopped so that we can check the value of JavaScript variables.
After checking, you can re-execute the code (such as the play button ).
Debugger keyword
DebuggerKeyword is used to stop JavaScript Execution and call the debugging function.
This keyword is the same as setting a breakpoint in the debugging tool.
If debugging is not available, the debugger statement cannot work.
Enable debugger and stop code execution before the third line.
Instance
Var x = 15*5;
Debugger;
Document. getElementbyId ("demo"). innerHTML = x;
Debugging tools for main browsers
Generally, the browser enables debugging tools by pressing the F12 key and selecting "Console" in the debugging menu ".
The steps for each browser are as follows:
Chrome
- Open your browser.
- Select a tool from the menu.
- Select the developer tool in the tool.
- Finally, select Console.
Firefox
- Open your browser.
- Access page:
Https://www.getfirebug.com.
- Follow the instructions:
Install Firebug.
Internet Explorer.
- Open your browser.
- Select a tool from the menu.
- Select the developer tool in the tool.
- Finally, select Console.
Opera
- Open your browser.
- The built-in debugging tool of Opera is Dragonfly. For details, visit the page:
Https://www.opera.com/dragonfly /.
Safari
- Open your browser.
- Access page:
Https://extentions.apple.com.
- Follow the instructions:
Install Firebug Lite.