Resolving JavaScript ‘Expected identifier’ Error in IE7 and IE8

January 16th, 2013 - Posted by Steve Marks to Javascript / jQuery, Web Development.

Whilst working with a JavaScript object earlier today I found myself coming up against an error in the JavaScript console that read as follows:

SCRIPT1010: Expected identifier

The error was only present in Internet Explorer 7 and 8, was a little unhelpful to say the least, and was showing to be occuring in a bit of code similar to the below:

myObject.class = 'myClass';

class‘ was a custom property of the ‘myObject‘ object that I had named myself and was using to store a value.

The Solution

The problem turned out to be that the word ‘class‘ is a reserved word in earlier versions of IE and therefore can’t be used when trying to store custom variables. I’d heard of using ‘className‘ before, but not ‘class‘.

After renaming the object’s property the script started to work immediately.

This entry was posted on Wednesday, January 16th, 2013 at 7:54 pm by +Steve Marks and is filed under Javascript / jQuery, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.

Fear not, we won't publish this

Comments (3)
  1. Mirek says:

    Thanks a lot.
    In my case it was .export (YAHOO.widget.export).

  2. Adrian says:

    Thank you for this post!

    My code was crashing because of “switch” word.

    $(“#cc_separator”).click(function() {

    It was very helpful to make this fix fast.

  3. Camelhive says:

    Thanks for your posting – it helped!

    My code crashed because of this usage of the reserved word “do”:

    function f(attributes) {
    if ( …)

    The workaround is to access object properties using quotes (attributes[“do”].firstProperty) or better yet – not use reserved words in object properties.