Request quote

IE7 error : SCRIPT1028: Expected identifier, string or number

Posted on: August 29th, 2012 by Sarath C 2 Comments

I just noticed today only, that the animated sliders in our home page is not loading in IE7 when I  logged in from my friends PC which was running in IE7.  Just did a casual visit to our website and found the sliders are not loading. I didn’t noticed it initially because most of our work stations are in either Safari or Chrome.  Got little worried on it, because most of the site users are still using IE7.  So I started to debug it. At first I could not think it as a javascript error because the same is working fine in all other browsers. After spending 20-30 minutes and changing each and every views, I could not find the source of error. So I thought of looking in to the javascript console for any valuable information and then only I noticed that the root cause is there. I got the following error in my IE7 Console

SCRIPT1028: Expected identifier, string or number common.js line 30 character 3

I checked the above line. But I could not find anything problematic there.

	$('#clients, #technologies, #services').nivoSlider( { 
		directionNav: false, 
		controlNav: false, 
		pauseTime: 5000,
		randomStart: true,
	});

So I started with the historical and MC Trial and Error method and  for my wonder, It got fixed when I removed the last “,” from the parameters array as follows.

	$('#clients, #technologies, #services').nivoSlider( { 
		directionNav: false, 
		controlNav: false, 
		pauseTime: 5000,
		randomStart: true
	});

It may appear the same to you. But look carefully at line 5 and you can see that, I removed the comma from the end of the last parameter.

var options= {
  parameter1 : 1,
  parameter2 : 2, // This comma is the problem!
};

So the error seems to be due to the trailing comma with no following values in the parameters array declaration. IE7 hates commas with nothing following them. FireFox and other browsers ignored the error, but not IE.

Reason 2 : When you are using a JavaScript Reserved Word as property name (Thanks to Mic Mcline)

When you assign a property named class to  the java script object. Class is a reserved word, and cannot be used as an identifier.

var options = {
    class: 'error'
};

The solution is  to pass the property of such reserved word as a string.

var options = {
    parameter1: 'value1',
    'class': 'error'
};

I lost thirty minutes on debugging it. Hope someone will find this useful and will have to spend only less time for finding and fixing the error than I did.

Tags: , , , ,

2 Responses

  1. Mike McLin says:

    There are actually 2 common reasons for this error. One is the extra comma, like you mentioned. Another popular trigger for this error is using a JavaScript reserved word. I actually created a blog post (and video) explaining the error, and how to fix it. http://mikemclin.net/fixing-error-script1028-expected-identifier-string-or-number/

  2. Team Webgalli'an says:

    Thanks for that info. :) Just updated the information.
    Ps : The video is good.