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:
Always run biome migrate after upgrading biome August 16, 2025 JavaScript
Video to Screenshots app June 21, 2025 JavaScript
Switching from Next.js to Vite + wouter July 28, 2023 JavaScript
An ideal pattern to combine React Router with TanStack Query November 18, 2024 JavaScript
Related by keyword:
Shout-out to eventlog October 30, 2014 Django
Why I gave up on JQuery UI's autocomplete October 20, 2010 JavaScript
Messed up columns in Django Admin October 16, 2009 Django
What makes my website slow? DNS October 23, 2009 This site, Linux