JavaScript programming JS Debugging _javascript Skills

Source: Internet
Author: User

This article mainly through an adder, introduced JS how to Debug. First code:
Effect:

Test.html:

<span style= "Font-family:comic Sans ms;font-size:18px;" ><! DOCTYPE html> 
 
 

Demo.js

<span style= "Font-family:comic Sans ms;font-size:18px;" >/** 
 * 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; 
} </span> 

Summary of Highlights:

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

A. With alert, the disadvantage is that every time the bomb frame

B. With Console.log, this is a small amount of data can also

C. Add Breakpoint Debugging

2, in JS, if the variable preceded by Var, representing local variables, function if the global variable without var. Therefore, in general, the variable is preceded with Var.

3, generally in the Chrome debugger, elements look at the code, in the source directory for debugging. In this mode, click on each line in JS can be added breakpoints.

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

5, in the breakpoint mode, input variables in the console can see the current value, at the same time you can modify the value.

The above is the specific steps of JS debugging, I hope everyone in JavaScript programming will use JS for debugging, thank you for your reading.

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.