Internet Explorer Javascript Error: “Expected identifier, string or number”

Posted on November 16, 2012

0


When browser testing for FlightCar, I came across this error twice! And I was stuck for a while, as there are actually (at least) two different instances for which this error can occur and our javascript suffered from both of them. (This error is prevalent in IE7-9, IE10 works perfectly fine as well as the other standard browsers.)

Case 1: Dangling comma:

Internet Explorer doesn’t like dangling commas, whereas the other modern browsers skip past this error. For example:

var photo{
picture = 7,
comment = 12, <!–remove extra comma–>
}

Case 2: Using a reserved key word in a dictionary:

In my case, this word was class.

I originally had:

{class:”input-append”}

IE wants your reserved word to be a string, so I changed it to:

{“class”:”input-append”}

Hope that helps!

Posted in: Web Development