A classic blunder in Javascript client side apps is heavy use of the incredibly useful Firebug feature that is console.log() and then forgetting to remove any such debugging and thus causing Javascript errors for people without Firebug. To remedy this use this little nifty function:


function log() {
  if (window.console && window.console.log)
  for (var i = 0, l = arguments.length; i < l; i++)
    console.log(arguments[i]);
}

That way you can do plenty of debugging and if you accidentally leave a logging line in your code it won't break anything even if they don't have Firebug installed/enabled. Also you can easily "annotate" your debugging by writing two things in one line. Like this:


function foo(bar) {
   log("bar is:", bar);
   return bar * 2;
}

Comments

kioopi

console.log can take multiple arguments. so it's possible to just apply all arguments of the custom log function to it:

console.log.apply(console, arguments);

Peter Bengtsson

Really?! That's cool. I'm going to try that.

Your email will never ever be published.

Previous:
In Django, how much faster is it to aggregate? October 27, 2010 Django
Next:
Worst Flash site of the year 2010 November 8, 2010 Misc. links
Related by category:
You don't need a context or state manager for TanStack Query in scattered React components January 2, 2026 JavaScript
How to handle success and failure in @tanstack/react-query useQuery hook September 16, 2024 JavaScript
gg2 branches got 50% faster by a Promise.all February 16, 2026 JavaScript
gg2 has a web page now January 5, 2026 JavaScript
Related by keyword:
Why I gave up on JQuery UI's autocomplete October 20, 2010 JavaScript
Shout-out to eventlog October 30, 2014 Django
What makes my website slow? DNS October 23, 2009 This site, Linux
YSlow grade A (96) but not with doubts August 6, 2007 Web development