Home > DeveloperSection > Blogs > JavaScript Debugging

JavaScript Debugging


JavaScript JavaScript 
Ratings:
0 Comment(s)
 1616  View(s)
Rate this:

JavaScript Debugging

Introduction:

In this article I will explain how we can find errors and correct it in JavaScript.

The script which we write in JavaScript may contain mistake, this mistake is known as bug and the process of finding and fixing bug is know as debugging. Debugging is a normal part of development process.

When working with JavaScript there are three main types of errors which are encountered:

1)      Syntax errors: A Syntax error refers to simple errors in code such as missing parenthesis etc.

2)      Runtime errors: Runtime errors are that error which occurs even when the script is a valid JavaScript code but there are some other mistakes such as variable not declared but we are trying to access it.

3)      Logical errors:  This errors is related to the logic, our program will compile and run but it will not give the correct output, as it must give. This type of errors are most difficult to find.

How to turn on the error message in the Browser:                                                                                               

By default Internet explorer shows an error icon in the status bar if any error occurs or we can turn on     this option from browser.

To enable this option in Internet explorer, Tools >> Internet Option>> Select Advance Tab                     

We can check this checkbox to enable the error message notification.

Error Message in Mozilla Firefox:

Other browser such as Mozilla, Netscape send error message to a special window called JavaScript Console.

We can view the console, select Tools>Web Developer>Error_Console.

These browsers give no indication when an error occurs; we have to keep the console open to view where error has occurred.

This is a console window which contains all the errors which are encountered during execution of script.

Error Notifications:

The error Notifications which shows up contains syntax errors as well as runtime errors.

Debugging Scripts:

We can check our JavaScript code for bugs, by allowing it to run through a program known as validating parsers which check JavaScript code is valid or not and syntax is valid or not. These programs comes with commercial HTML or with various JavaScript Editors.

How to Add Debugging code to our program:

We can manually insert alert() or document.write method to debug our code so that we can see the order of execution of our  code and can examine where the errors appear.

JavaScript Debugger:

We can also use JavaScript Debugger, a debugger is an application that places the script execution under the control of the programmer. Once the script is loaded into the debugger then we can examine code line by line and checking the state of variables

Conclusion:

In this article I explained Debugging in JavaScript because bugs appears in the program and we need to find and fix it through one of the debugging techniques.


Don't want to miss updates? Please click the below button!

Follow MindStick