Problems with console.log(), jQuery, and Firebug in Firefox

Posted on

Today, I’m just going to let you all in on a secret that I found out, hopefully it will save some of you some time and headaches. The other day I was working on a website and I was having some problems with the way my JavaScript was working. It was acting like I forgot a semicolon or something. So I started debugging and I finally found out why it was acting up. If you are familiar with the Firefox plugin Firebug, then you may also be familiar with console.log().

Basically, what I noticed was that if you do not have your Firebug window open, your JavaScript will break as long as you are using anything to do with the console object. This is because Firebug introduces this variable into the document and therefore when Firebug is not open it is not defined and as a result, will break your script. There are a couple ways to fix it. You can simply comment it out while not using Firebug, or you can check to see if window.console is defined.

I hope this has helped some of you. I know this frustrated me for a bit before I discovered the problem.

Happy Coding!