NetEase front-end cloud classroom, JavaScript programming: JS debugging

Source: Internet
Author: User

This section mainly through an adder, describes how JS debugging. First on the code:

Test.html:

<! DOCTYPE html>

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:


Class Summary:

1, general debugging JS, printing information has the following three kinds:

A, with alert, the disadvantage is that each time the frame

b, with Console.log, this small amount of data can also

C, add breakpoint debugging

2, in JS, if the variable is preceded by a Var, indicating a local variable, function if not with VAR to represent the global variable. Therefore, in general, variables are preceded by var.

3, generally in the Chrome debugger, elements look at the code, in the source directory to debug. In this mode, you can add breakpoints by clicking on each line in JS.


4, in debug mode the rightmost four buttons are: The next breakpoint, step into the next function, jump out of the function. All of the basic debugging tools have these four kinds.


5, in the breakpoint mode, enter the variable in the console to see the current value, while you can arbitrarily modify the value.

NetEase front-end cloud classroom, JavaScript programming: JS debugging

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.