Soft Technology Web Classroom: Important -> JavaScript Debugging

Error will always occur whenever you write some new computer code when.

JavaScript debugging

In the absence of written JavaScript debugger situation is difficult.

Maybe your code contains syntax errors or logic errors, which are difficult to diagnose.

In general, if JavaScript code contains errors, it will not happen anything. No error message and does not look for any indication of an error message.

In general, whenever you try to write a new JavaScript code, errors may occur.

JavaScript Debugger

Find a programming error in the code is called code debugging.

Debugging is not simple. But fortunately, all modern browsers have built-in debugger.

Built-in debugger can be opened or closed, forced to report the error to the user.

Through the debugger, you can set breakpoints (code execution is interrupted position) and check the variables in the code execution.

Usually start the browser debugger via the F12 key, then select "Control Panel" in the debugger menu.

console.log () method

If your browser supports debugging, you can use  console.log () JavaScript displays the value in the debug window:

Examples

<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>

<script>
a = 5;
b = 6;
c = a + b;
console.log(c);
</script>

</body>
</html>

 

Note: Please visit our JavaScript Console Reference Manual for more information about the console.log () method.

Set a breakpoint

In the debug window, you can set breakpoints in JavaScript code.

In each breakpoint, JavaScript will stop execution so that you can check the value of JavaScript.

After checking the value, you can resume code execution.

debugger Keywords

Keywords debugger will stop execution of JavaScript, and calls (if any) debugging functions.

This set a breakpoint in the debugger functionality is the same.

If the debugger is not available, Debugger statement has no effect.

If the debugger is open, this code will stop running before executing the third line.

Examples

There are x = 15 * 5 ;
debugger;
document.getElementbyId("demo").innerHTML = x; 

Mainstream browser debugging tools

Typically, you enable debugging through F12 keys in your browser, and select "Control Panel" in the debugger menu.

Otherwise, follow these steps:

Chrome

  • Open your browser
  • Select Tools from the menu
  • Select the tool from the tool developer
  • Finally, select Console

Firefox Firebug

  • Open your browser
  • Go to the page: http: //www.getfirebug.com
  • The instructions for: How to Install Firebug

Internet Explorer

  • Open your browser
  • From the menu, select Tools
  • Select Developer Tools from the Tools
  • Finally, select Console

Opera

  • Open your browser
  • Go to the page: http: //dev.opera.com
  • The instructions for: How to Install Firebug Lite

Safari Develop Menu

  • Click the Safari menu, Preferences, Advanced
  • Select the "Enable Develop menu in menu bar."
  • When the new option "Developer" menu appears, select "Show Error Console"

Do you know?

Debugging is testing a computer program to find and reduce the process of bug (error) of.

History's first known computer bug is a card in an electronic device of the true bugs (an insect).

Guess you like

Origin www.cnblogs.com/sysoft/p/12066136.html