Javascript Bug in Mozilla Firefox

Mike BerrymanI recently ran into an issue with a javascript element appearing incorrectly in Firefox. If you don’t know, in javascript you’re able to define a function after the line number that you actually call it in the code. This is possible because the browser (whichever that browser may be) will parse through the javascript before running any of it. This is to ensure that syntax is valid, memory is properly allocated, and the browser properly understands the function you declare so it knows what to do when the function is called.

HOWEVER, if you have a function declaration within an if block, AND said declaration occurs after you try to use it, Firefox won’t understand the function and throw an error.

For example, the following function will appear fine in browsers like Chrome and Internet Explorer:ffjavabug.JPG

On the other hand, in Firefox, the doSomething(); portion will be undefined, causing an error.  So make sure all your function declarations occur before the function is called for the first time!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s