console.log without firebug

By Simon Varney on 21 Nov 2008

console.log is an invaluable javascript logging function which is part of firebug in firefox.

But I’ve been bitten a few times after running the javascript in a browser without firebug as it tries to call a function that does not exist.

A quick and easy solution is create a basic javascript function that can be called in the same way as console.log, such as:

if (typeof console=="undefined"){console={log:function(A){var B=false;if(B){alert(A)}}}}

Nothing ground breaking! – and in this version all log messages are discarded, set B to true to have them pop up in a javascript alert box.

If you need more sophisticated javascript debugging that will work in most browsers then check out firebug lite.

(…if you haven’t heard of firebug and are doing any sort of client side web development then get it)