Javascript Debugging with Firebug's Console

For as long as I've been developing in JavaScript, my debugging mainly consisted of alert()'s, [[HTMLParagraphElement]].innerHTML's, and [[HTMLInputElement]].value's... that's until Firebug's (Firefox extension) Console implementation came along. Even thought I've been a heavy user for a while now, I'm still discovering more features and tools to help me along my way. If you're a developer and don't have Firebug, you need to get it and if you have it but don't use the console, you need to start using it! Bottom line, if Google Chrome and IE8 have similar implementations, you know it's good. Let's have a look at the basics of utilising the console logging.

 

Open up Firebug and select the Console tab. 

 

At the bottom of the console, enter console.log("Hello World")

 

Firebug 01

 

Hey! You get "Hello World" as the output.

 

Let's try something a little different... enter console.log("My output text is %s" , "Hello World")

 

Firebug 02

Now try this:

var a = 1, b = 2, c = a + b;
console.log(a, b, c);

 

Firebug 03

 

You can also output messages with different return styles. Useful in try-catch blocks and exception handing.

console.debug("debug");
console.info("info");
console.warn("warn");
console.error("error");

 

Firebug 04b

 

Now try this with actual HTML implementation. Let's find the number of list items in the unordered list.

 

Firebug 05b

 

 Firebug 06

 

Display arguments passed to a function


Firebug 07


Firebug 08a

 

Select 'more...'

 

Firebug 08b

 

Visually group HTML Elements

 

Firebug 09a

Firebug 09b

 

Return tree structure of an HTML Element

Firebug 10a

 

Firebug 10b

 

Measuring the execution time for your function using console.time();

 

Firebug 11a

Firebug 11b


A details result returning precise measurements using console.profile();

 

Firebug 12a

Firebug 12b


These are just a few examples of some of the things you can do with Firebug's console and I recommend looking into it in more detail. Some recommended reading...

http://getfirebug.com/logging
http://getfirebug.com/wiki/index.php/Console_API
http://michaelsync.net/2007/09/09/firebug-tutorial-logging-profiling-and-commandline-part-i/
http://net.tutsplus.com/tutorials/other/10-reasons-why-you-should-be-using-firebug/

+ Back to blog home

Posted in: Tips and Tricks, JavaScript

 
Thanks for reading! blog | catalog