JavaScript Error: Expected Identifier in IE

If you are getting ‘Expected Identifier’ JavaScript error on IE this means you have some conflict with Mr. Gates :)

Okay to the point, this can happen due to two reasons (as per my knowledge, let me know if you know something else):

1. Some typing mistake in your code

var myVar = {
function1: function() { // some code },
variable1: ‘Some value’,
variable2: ‘Another value’,
};

Notice the extra comma after the last variable defined just before } braces, Firefox will ignore this but IE will not. Lets move to second reason.

2. You have used reserved keyword in your code mostly as variable name Just yesterday, I got this error on IE due to some old written JS code. First I tried to find the code mistake but after looking at the code with a sharp eye I found that some reserved words were used. Following is the code I corrected

obj.class = ‘up’; ///this works in Firefox
obj.className = ‘up’; ///this is the correct implementation

var onloadstat = 0; //works in FF but in IE its a reserved keyword same as ‘class’

At the end, if you get the ‘Expected Identifier’ JS error in IE first look for these mistakes. You will be able to fix the error quickly.

Leave a Reply

Your email address will not be published. Please enter your name, email and a comment.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">