Home  >  Article  >  Web Front-end  >  How to debug javascript

How to debug javascript

coldplay.xixi
coldplay.xixiOriginal
2021-04-08 14:38:002892browse

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.

How to debug javascript

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn