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