console.log(‘just say no to alerts’)
by Sue
If you are using alerts to figure out what’s going on in your code, you need to quit it. If you’re like me, sometimes those alerts say things like
alert("OMFG Why are you not catching you piece of crap. I hate your stupid face");
or the super fun “I wonder what this variable is returning…” alerts that may or may not contain 1000 data point sets and create the scariest looking popup ever.
And woooo, can you imagine if that accidentally get’s pushed so a client can see it. I wish I had a funny story about that happening, but beyond a team member accidentally writing Blah on a test page and it getting pushed, I haven’t had first hand experience.
Anyway, instead of alert, use Firebug, open console and in your code write
console.log("OMFG Why are you not catching you piece of crap. I hate your stupid face");
Oh noes, but what about when IE is my debugging nemesis! Well don’t worry because Firebug lite is there to help you out.
And if you need even more from your console.logs like history and preventing array wrapping, you can use helpful wrappers like this one that Paul Irish made.
Chances are that if your logs accidentally get pushed and the client opens firebug and sees them, they are probably another idev working long tiring hours for the man and you can high5 about it sometime and talk about your favorite stackoverflow threads and the cutest cats of reddit. Also don’t forget the try and catch, so having an uncommented out console.log in your final code doesn’t break your site.
TL;DR
Using alerts to test code is a bad idea.
Using console.log might make you super friends.
Comments
I know I’ve told you the horrific story of the first time I learned NOT to output debug strings to an application. It wasn’t pretty. It was also caught ten minutes before the client showed up for a review. Oops :/.
Let this be a lesson kids – don’t code too late at night before a tight deadline and spit out rubbish in your code.
alert(‘ffffff UUUUUUUUUU’);