Friday, March 21, 2014
So for example:
If/Then statements and Firefox
The problem is in Firefox if you define a function inside an if/then statement the function no longer gets hoisted. This only happens in Firefox.
So in the following example, the following code works in IE and Chrome but is broken in Firefox.
In Firefox I get an error because it did not hoist the callHoistedFunction therefore it was not defined at the point it was being used.
So the moral of the story is never define a function inside a “if/then” or “try/catch” statement. As a matter of practice, you should probably just define all variables and functions at the top of the outer function as that is where it gets hoisted to anyways.
Here is his video on his book in case you were also interested.
Hope this helps,