JavaScript – IE 7 Error: Expected identifier, string or number

This is a common error when debugging JavaScript for the IE 7 and earlier IE browsers. Essentially, it appears that IE 7 is a little more strict on syntax than IE 8 and it's successors.

While this error is not specific to JSON formatted objects, it can occur when they are not syntactically correct. When dealing with JavaScript Object Notation, ensure that you don't have any "trailing commas". For instance, the following will throw an error in IE 7:

var  customLayout: {
            'test1' : [ '0 1 2 3 4 5 6 7 8 9'],
            'test2' : [ 'q w e r t y u i o p'],
}

Whereas, this JSON object is valid (notice that the final element is not suffixed by a comma:

var  customLayout: {
            'test1' : [ '0 1 2 3 4 5 6 7 8 9'],
            'test2' : [ 'q w e r t y u i o p']
}

Why follow me on Twitter?

  • I tweet about new technologies, services or libraries I find interesting
  • Yeah, sometimes I'll post a pet-peeve or rant about something trivial
  • If I discover something that made my web development life easier, I share it
  • I'll shout out any handy tip that I think might be useful to other devs
  • Very rarely anything promotional


Tagged , .

Updated: 2011-12-31

Phil LaNasa follow us in feedly