Debug JavaScript in Chrome

Source: Internet
Author: User
Tags chrome developer chrome developer tools

In the previous two articles we talked about debugging JavaScript in IE and debugging JavaScript in Visual Studio, in this article we'll talk about how to debug JavaScript in Google Chrome.

Chrome is a very good browser provided by Google, built-in developer tools, so that we can easily debug the JS code. With the experience of using IE to debug JavaScript, it's easy to debug with chrome.

Use Chrome to open the page we want to debug, and then use the shortcut key F12 to open the developer tools, and of course you can find it in the Tools menu. Chrome Developer Tools

The Elements tab is the selection of elements on the interface, and the code we want to debug is in the Sources tab.

Open the Sources tab and click on the small arrow on the left to open all the resources and select our page:

We want to debug the code for this page, so just open this page and click on the line number to add a breakpoint:

By clicking the button in the interface, we can capture the breakpoint we just added:

The method to add monitoring is the same as in IE: Select the variable, click on the variable, and select "Add to watch", such as:

Monitoring of variable A has been added to the monitoring window on the right:

After executing this sentence, the value of a will change:

Google Chrome debugging JavaScript shortcut keys:

F10: Step over, that is, skip the method, expression, etc. in the statement

F11: Sentence-by-statement debugging, that is, single-step debugging, will jump into the method, the expression, the statement-by-track debugging

These two function keys operate the same way except for the absence of a F9.

If you want to execute code temporarily in Google Chrome, you need to edit and execute the temporary code in the console that opens the code:

We enter alert (a), then enter, and a prompt will pop up on the interface, such as:

If you want to stop debugging, simply close the developer tool.

Debug JavaScript in Chrome

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.