2/75, Hope St
South Brisbane
Qld 4101, Australia
T. +61 (0) 7 3844 0001
F. +61 (0) 7 3844 1001
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")
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")

Now try this:
var a = 1, b = 2, c = a + b;
console.log(a, b, c);
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");
Now try this with actual HTML implementation. Let's find the number of list items in the unordered list.
Display arguments passed to a function
Select 'more...'
Visually group HTML Elements

Return tree structure of an HTML Element
Measuring the execution time for your function using console.time();

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

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/
Posted in: Tips and Tricks, JavaScript