The traditional method of debugging Javascript in the browser involves using the alert method to display a dialog box. Clicking OK for the 100th or attempting to debug browser events will soon have you ready for a new approach.
Firebug has a handy console pane which displays erros and allows you to enter Javascript and execute it immediately.
Using Firebug's console API you can also log messages to the console from within your browser scripts and avoid the pain of repeated alert dialog boxes.
The log method takes an argument and prints it in the console.
console.log('Total price is');
console.log(totalPrice);
Several arguments can be passed and Firebug will join them together, separated by a space:
console.log('Total price is $', totalPrice, ' and the time was ', transactionTime);
console.log() will take an object, too, but a better choice can be console.debug();
console.debug(window.location);
The debug method automatically creates a link in the console window. Clicking the link in your Firebug console takes you to the DOM inspector for that object.
For small objects it can be useful to show their contents right here in the console window.
console.dir(window.location);
There are several more console methods available. Read through the Firebug Console API documenation to find out more.