Console.log is your friend


Although it only works in Chrome and FireBug, I’ve found console.log() to be an extremely handy tool for debugging javascript without having to step through code.

Here’s a bit of code I’ve found handy to make sure browsers without console.log don’t bomb out in case you forget to take your console.log statements out:

if (window.console == undefined) { window.console = {log:function(){},dir:function(){}}; }

Make sure to add this near the top of your scripts and you’ll be able to use console.log without fear of it causing problems in browsers like IE.

No related content found.

Share

Leave a comment