1. Debugging and testing
Modality and testing are actually similar, but the object is different. Testing is oriented at product level and system level; Debugging is usually a part of a program, a method, a property or an object. The end result is similar, good testers, test solutions can solve the problems of the product system in the cradle; A good debugging method will also give you a deep understanding of how the program is running, make it easy to locate problems, and make the software run more stable.
2. The Console debugging method
2.1 Adding the console.log command
Add the console.log() method to the code. Here the example outputs the highest and lowest values that are read back from the database as follows:
2.2 The output temperature screen is as follows
2.3 Console Window of Google Chrome
In Google Browser, press F12 to bring up the Console window shown below.
2.4 the console. The error output
Change the code to Error and output the following
2.5 Browser Output
The browser’s Console output turns red as follows.
If the output is a JS object or array, it needs to be converted to a JSON array using the json.stringify method, as shown belowconsole.log(JSON.stringify(resolve));
3. Alert the debugging method
3.1 Alert method code
3.2 Effect of alert
Note: The alert method blocks and the front-end code will not continue until you click OK
4 Breakpoint debugging method
4.1 Setting a Breakpoint
Set the breakpoint debugger as shown in the following figure
4.2 Running Code
After running the code, it automatically jumps to the breakpoint and stops running as follows
4.3 Entering the desired attribute
4.3.1 Observe data in Watch
Watch center point “+”, and then click Enter to see the corresponding data value.
4.3.2 Viewing Data on the Console
F12 Select the browser Console window, enter the name of the variable to be observed, and press Enter to view the corresponding value.
4.4 Enter the method you want to execute
After the breakpoint is set and stopped, the method before the breakpoint can run output in the Console window.
4.4.1 Write a debugging method output()
4.4.2 Set breakpoints and run the program
See 5.1 and 5.2 for details
4.4.3 Execution Method Run the program
The execution result is as follows.