Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

JavaScript Debugging Techniques with Firebug

By Akash Mehta
2008-04-20


General debugging

For general debugging, there are a number of simple strategies that can help you easily identify errors and construct code that is more error-proof.

Isolate issues

Commenting out large chunks of code can help isolate the problem. You can use either comment blocks (/* and */), or wrap an if (0) { ... } around your code. The problem with comment blocks is if you try to comment out a block of code with a comment block in it. An if (0) will remove code in a JavaScript-valid manner to make sure it is never executed.

Google it

If you are attempting to achieve a particular complex task in JavaScript, and have trouble with your approach, try googling the issues. Chances are someone has done what you are attempting before, and has documented common problems and solutions somewhere on the web. They may even provide code that serves the purpose.

console.log()

Both Firefox and Safari (and many other browsers) provide a JavaScript console to which you can log data. Instead of alert popup boxes and writing variable values directly to the document, try calling console.log() with your debug data. This allows you to record information as your script executes and identify the issue. If you need this to work on Internet Explorer or other browsers, try Firebug Lite.



Tutorial Pages:
» Understanding JavaScript errors
» General debugging
» JavaScript debugging tools
» Debugging syntax errors
» Debugging runtime errors
» Debugging logic errors
» Further reading


Related Tutorials:
» Striped Tables Using JavaScript
» Opening PDFs in a New Window with JavaScript
» Essential Javascript -- A Javascript Tutorial
» Submit Forms Conditionally using JavaScript
» How to Setup a Randomising Function
» Introduction to JavaScript Tutorial