Logging in Javascript

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com, or follow me on Twitter.

I haven’t done much Javascript work since 2009 (when I built an awesome calendar system that was never used in production, sad to say). I know this scene is changing dramatically. One of the big problems used to be getting decent feedback on where the errors in the code was. Now Firebug has some good logging tools:

Firebug and Logging

Having a fancy JavaScript debugger is great, but sometimes the fastest way to find bugs is just to dump as much information to the console as you can. Firebug gives you a set of powerful logging functions that you can call from your own web pages.

Your new friend, console.log

The easiest way to write to the Firebug console looks like this: console.log(“hello world”)

You can pass as many arguments as you want and they will be joined together in a row, like console.log(2,4,6,8,”foo”,bar).

Post external references

  1. 1
    http://getfirebug.com/logging
Source