Netease front-end micro-Professional, JavaScript programming: JS debugging

Source: Internet
Author: User

Netease front-end micro-Professional, JavaScript programming: JS debugging

This section describes how to debug JS by using an example. First run the Code:

Test.html:

 

  Calculator + = Computing<Script src = "./demo. js"> </script> 

Demo. js

 

 

/** * Created by yanzi on 15/12/8. */var num1 = document.getElementById("num1"),    num2 = document.getElementById("num2"),    result = document.getElementById("result"),    btn_add = document.getElementById("add");btn_add.addEventListener("click", onAddClick, false);function onAddClick(){    var a = parseInt(num1.value),    b = parseInt(num2.value);    var sum = add(a, b);    result.innerHTML = sum;}/** * * @param a * @param b * @returns {*} */function add(a, b){    return a+b;}

 

Effect:

Classroom summary:

1. In general, there are three types of JS debugging and printing information:

A. Use alert. The disadvantage is that the dialog box is displayed every time.

B. You can use console. log to handle a small amount of data.

C. breakpoint debugging

2. In JS, if var is added before the variable, it indicates the local variable. If var is not included in the function, it indicates the global variable. Therefore, the variable is usually preceded by var.

3. In the chrome debugger, elements looks at the code and debug it in the source directory. In this mode, you can click each line in js to add a breakpoint.

4. In debug mode, the four buttons on the rightmost side are: Next breakpoint, one-step execution, go to the next function, and jump out of the function. Basically all debugging tools have these four types.

5. In breakpoint mode, enter a variable in the console to view the current value, and modify the value at will.

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.