How to more easily debug JavaScript code

Source: Internet
Author: User
Developer Tools

Now the General browser has built-in developer tools, shortcut key F12 can be opened, such as Chrome browser, under the sources panel to find the corresponding JS file

This is the preferred method, but for spa programs (such as Easyui), inline pages may not be found. So if it's a spa program, you might want to think about other methods.

vs Next Breakpoint at JS code

This method is not used for spa inline pages, but you can use the Debugger keyword to set breakpoints manually , as follows.

If you use IE, you need to first remove the two options, and then F12 open the developer tools, using chrome just open the developer tools. This method is useful for debugging Spa single-page programs such as Easyui.

using Console.log

You can print the value of a variable to the console, which allows you to navigate to the line of code where the error occurred.

Before using the Console.log method, there is also the use of the alert method to debug, but the use of too inconvenient, debugging also need to delete, the code is intrusive, not recommended to use.

View the results.

Summarize

1, if it is a normal website (non-spa program), use the first method is best.

2, if it is a spa single-page program, using the debugger keyword to manually set breakpoints is most convenient, but after debugging or to manually delete.

How to more easily debug JavaScript code

Related Article

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.