Home > Article > Web Front-end > How to debug javascript
How to debug JavaScript: 1. Use the [console.log()] method to print the JavaScript value on the debugging window; 2. Use the debugger keyword to stop executing JavaScript and call the debugging function.
The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.
Methods for debugging javascript:
1. console.log() method
If the browser supports debugging, you You can use the console.log() method to print JavaScript values on the debug window:
Instance
a = 5; b = 6; c = a + b; console.log(c);
2, debugger keyword
debugger keyword Used to stop executing JavaScript and call debugging functions.
This keyword has the same effect as setting a breakpoint in the debugging tool.
The debugger statement will not work if no debugging is available.
Enable debugger and the code stops executing before the third line.
Example
var x = 15 * 5; debugger; document.getElementbyId("demo").innerHTML = x;
Related free learning recommendations: javascript learning tutorial
##
The above is the detailed content of How to debug javascript. For more information, please follow other related articles on the PHP Chinese website!