Home > Web Front-end > JS Tutorial > body text

How to debug javascript

coldplay.xixi
Release: 2023-01-04 09:35:13
Original
2891 people have browsed it

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);
Copy after login

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;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template