Skip to content Skip to sidebar Skip to footer

Missing Semi-colon In Javascript Causing "'foo' Is Undefined" Error In Ie9

I just spent about four hours tracking down this problem. I know what is causing it but don't know why and the 'why' is bugging me. I have the following .js file: function funcA()

Solution 1:

Unfortunately, JavaScript does not require you to explicitly put in semi-colons everywhere that there should be one - but it will internally put those in for you. This can often lead to hard to trace bugs and unexpected behavior.

Among other syntax errors in your code (as others have pointed out), the ; after the while in a do-whileis required and when you put in there, things work as you expect them to. When this isn't done, it's pretty much impossible for the casual developer to predict how different environments will behave without digging deep into the specs of the language and the JS engine and understanding it all - assuming there are no bugs in the implementation of the JS engine itself. Little things such as whether you have braces ( { and } ) in the same line or not can make a difference.

Solution 2:

From my reading of the ECMAScript spec, IE's behavior is correct. See sections:

  • 7.9.1 Rules of Automatic Semicolon Insertion (which describes the cases in which a semi-colon may be inserted, none of which apply)

  • 12.6.1 The do-while Statement (which shows that your code is not a valid production of the form do Statement while ( Expression );

Post a Comment for "Missing Semi-colon In Javascript Causing "'foo' Is Undefined" Error In Ie9"