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:
How to handle success and failure in @tanstack/react-query useQuery hook September 16, 2024 JavaScript
An ideal pattern to combine React Router with TanStack Query November 18, 2024 JavaScript
Starting a side project: PissueTracker March 16, 2025 JavaScript
How to SSG a Vite SPA April 26, 2025 JavaScript
Related by keyword:
Why I gave up on JQuery UI's autocomplete October 20, 2010 JavaScript
What makes my website slow? DNS October 23, 2009 This site, Linux
Shout-out to eventlog October 30, 2014 Django
YSlow grade A (96) but not with doubts August 6, 2007 Web development