JavaScript Error ‘expected identifier, string or number’ in IE

Posted: February 7, 2011 in How To

Sometimes you get those errors that just pick at you and you can’t seem to find a solution. It happened to me this morning when testing a JavaScript library I’m writing in IE7. FireFox worked without a hitch, but IE threw an ‘expected identifier, string or number’ error pointing to the last line of the variable declaration. Of course it didn’t help that my copy of MS Script Debugger wanted to lock up my computer.

 

Here’s a very shortened example of the code I was working on.

JavaScript:

  1. var variableName =
  2. {
  3. function1:   function()
  4. {
  5. //  Do something
  6. },
  7. function2:   function()
  8. {
  9. //  Do something else
  10. },
  11. variable1:    ‘Some value’,
  12. variable2:    ‘Another value’,
  13. };

The error was reporting a problem on line 13. So after hacking my way around trying to figure out why it was giving me this error, I went out Googling. About 10 pages into the search results I found the solution.

Look at line 12. See the comma after ‘Another value’? That’s what was causing the error. I had taken out a variable under that one but forgot to remove the comma. FireFox ignored the error, but not IE.

One little misplaced character, so much wasted time. Hopefully y’all will spend less time finding the fix than I did.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com 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