Internet Explorer Javascript Errors

July 21st, 2006

Evolution and Geneone have been plagued by some Javascript errors in Internet Explorer over the last few weeks. To be honest, the number of people who play Evolution or visit my blog using IE are so low that no one has actually bothered complaining.

These errors included Object expected and "Expected identifier, string or number". I’ve never tried to actually fix these errors before because IE’s script debugging really really sucks. 

Windows Scripting Debugger can be a useful tool for debugging Javascript but be warned that it is very very unstable and severely affects the stability of your computer.

Expected identifier, string or number

This was an annoying little bug caused in a class because of a comma at the end. In Javascript you have lists like:

var list = { opacity: 0.5, height: 0.5} 

Similar syntax is used to group functions:

var MyFuncs = {bleh : function() {},bleh2 : function() {},} 

The above code should work fine in real web browsers such as Firefox. IE will give a screwed up error such as "Expected identifier, string or number". Just remove the comma after the last function and the error be gone.

Object Expected

If you document.getElementsById(’nonexistantitem’) in Firefox and try to retrieve an attribute such as previousSibling, Firefox won’t complain. IE will. This was causing issues as I had a little bit of Javascript which searched for the "Entry Title" box above the "Message" box in the Object Creation forms. On pages where the Entry Title field weren’t shown, IE would freak out as the previousSibling would return False.

I should thank neonDragon for his assistance in resolving these issues

  1. It’s rewarding being a blogger
  2. FireBug
  3. Annoying things about PHP
  4. Gene_Template
  5. Merlin: A way to annoy visitors using Internet Explorer

37 Responses to “Internet Explorer Javascript Errors”

  1. Peter Goodmanon 22 Jul 2006 at 6:50 am

    The actual syntax is:

     var list = {

     a: function() {

    },

    b: "some value"

    }; 

     

    (note the semicolon at the end)

     

    Also, it’s good practice to actually error check your code.. e.g.:

     

    var elm = document.getElementById(’whatev’);

     

    if(elm) { … } 

  2. Peter Goodmanon 22 Jul 2006 at 6:52 am

     P.S.You should check out JSLint, it will help you debug your javascript.

     

  3. Khloon 22 Jul 2006 at 12:14 pm

    Ah cool, thanks for the information. The problem was I was trying to look for the element which came 2 places before a specific element. So I had code like:

    document.getElementById(’magnets’).previousSibling.previousSibling.previousSibling.previousSibling.

    It was possible that .previousSibling.previousSibling didn’t exist so I had to check for that before calling previousSibling again twice.

    Thanks for the info about JSLint, should come in really handy! 

  4. Chris Iuferon 23 Sep 2006 at 12:28 am

    awesome. saved my butt when all was lost… these IE error messages just never help.

  5. Chrison 06 Nov 2006 at 5:18 pm

    Thank you for posting this.  I have a JSON object that is >60K and it would have taken me forever to find that I have an extra comma at the end.  You just saved me a ton of time.

  6. Gerald Deutschon 20 Feb 2007 at 12:32 am

    You went probably way too far - too much bother to fix that as interestingly enough its mostly M$ own sites that also trigger that error message (my favourite being their beta site). Don’t know, dear Microsofties but you happen to test your own web pages with firefox? It WOULD be clever to do so, I’d grant you that

  7. David Conradon 28 Feb 2007 at 8:29 pm

    Thank you, thank you, thank you! I just spent half an hour or more wrestling with the "Expected identifier, string or number" error!

  8. Yuriyon 18 Jul 2007 at 12:26 am

    thanks for this article, helped me with my problem!

  9. Slavaon 17 Aug 2007 at 8:26 am

    Thanks very much for the article.

    I almost crushed my head figuring out what is wrong with my code. The most nasty thing is that Explorer has allowed code to be executed partly, which really disturbs and hides the problem.

  10. Andyon 28 Aug 2007 at 3:56 pm

    Know this was prob an old post but I just wanted to thank you for this  stumbled  upon your blog via google. Thanks a mill  spent way too long trying to figure that one out! IHATE IE!!!

     But thanks :)

  11. Remon 10 Oct 2007 at 3:01 am

    Thank you! Your article helped me fix an issue developing some Javascript in IE.

  12. Saikrishnaon 25 Oct 2007 at 8:17 am

    Thanks a million for this post. You are a lifesaver !

  13. Yeeon 25 Oct 2007 at 10:37 am

    Thank you, thank you.
    You saved me plenty of time and hair-pulling.
    Bloody little comma, who would’ve known.
    And the useless error message doesn’t help.

    Thanks again.

  14. Hughon 28 Dec 2007 at 3:01 am

    I’d like to add another Thank You!  Been fighting a stupid IE error for hours, thanks to this page I tracked it down to a trailing comma in an AJAX data array, about a thousand lines away from where IE was bitching about, in a totally different function!

       — hugh
     

  15. Cars For Saleon 24 Jan 2008 at 11:57 pm

    I am using similar kind of editor as this is used for comments typing. I am adding this javascript editor in my website. The problem is if I put some comma like this ( ‘ ) and save in database. Again when i click to edit these text then it won’t show the textarea with value getting from database. Without comma ‘ it works ok.

     

    Is there any solution or fixes in javascript. thanks 

  16. Zackon 28 Feb 2008 at 10:36 pm

    Ah, I love the internet. You just solved a very perplexing problem I was having in IE. Argh, ye blasted comma! Anyway, cheers –

  17. [...] down the problem causing obscure “Expected identifier, string or number” errors. It turns out that it was caused by having a comma after the last element of a list, e.g. 1 2 3 4 5 6 7 var list [...]

  18. Fadion 03 Apr 2008 at 6:10 am

    hi

    I just want to say thank you so much for the information

    i was fighting this bug for about 1 - 2 hours until i found the f***ing comma after searching at the almost the end of the function , now everything is work well

    thanks again

  19. Hodgeon 20 Apr 2008 at 1:57 pm

    2 bugs down… 369,532 to go… If only the rest of the world would use Firefox, eh?

  20. RQon 08 May 2008 at 8:46 am

    Gee, this posting just solved a problem I was having. I had no clue that this comma I accidently left at the end of an array would break IE. Thanks! :)

  21. [...] two years ago, I experienced an persistent error in my Javascript development in one of my scripts. It was the case of the “Expected [...]

  22. Naokoon 21 May 2008 at 1:49 pm

    OH Just Thank you so much for your post….
    You have saved me tons of time.

  23. sivaon 24 May 2008 at 3:40 am

    “Expected identifier, string or number” error comes if we have null has key in some object. E.g.: {null:”TEST”}

  24. Parag Desaion 04 Jun 2008 at 12:58 pm

    You can try using Other Alternate Browsers, if problem is really with your Internet Browser or the system.

  25. Yuraon 06 Jun 2008 at 4:03 pm

    I use http://www.goodbyeie6.org.ua/ and forgot about IE6. Plus my users downloads new browsers.

  26. Zackon 17 Jun 2008 at 5:03 am

    Thank you for posting this. I have spent way too many hours trying to get things to work in IEEEEEEEEE (sorry to scream). I think you hit the nail on the head when you talked about internet explore being hard to debug scripts, they are virtually impossible.

  27. Nigel Hillon 15 Jul 2008 at 7:25 am

    It’s for this reason, and that it’s easier to append and they always fall in the same column on the page, that I put the commas at the start of lines instead of the end.

  28. nsswagaon 25 Aug 2008 at 1:20 pm

    Thanks for this info. Saved me time too

  29. Frantaon 09 Oct 2008 at 11:42 am

    Thanks, this helped me solve the ‘object expected’ problem.
    Does anyone know what the line number in IE javascript error messages refer to? They don’t ever seem to help me find the particular line that contains the problem.

  30. Peteon 02 Nov 2008 at 4:20 am

    Well guys, actually the IE version is correct as any real programmer knows. The comma is a separator and by inference it follows that after a separator comes another field.

    Now if the the fieled is NULL, which is different from an empty string then of course the program breaks and throws an error.

    Firefox have just handled the exception in a nice way. That said, masking the exception just makes browers more tolerant for the great unwashed. We professionals should still observe the programming rules for accuracy and potential reuse in other environments.

    Cheers

    Peter

  31. el_fabrion 09 Nov 2008 at 11:56 am

    Man , you saved my life , those errors were driving me nuts !!!! until i found this blog and the errors were gone , big thanks for you. keep doing a great job.

  32. Ashok Ramchandanion 08 Jan 2009 at 6:35 am

    Error: Expected identifier
    One more reason for error message saying “Expected identifier” is when we use some reserved keyword in our javascript code. I encountered the same problem. My code was somthing like:

    testFunc = function (test, class) {

    }

    IE gave me error saying “Expected Identifier”. As the error message is not very descriptive I had a tuff time finding out the solution. The actual problem is class is a reserved word in IE browser so we can’t use it in our javascript code.

  33. cailieon 06 Feb 2009 at 6:22 pm

    I award you my “Hero of the Day” award. Thank you!

  34. Sasha T.on 13 Feb 2009 at 12:50 pm

    Yap, IE hates commas (,) on everything… I was lucky enough for IE to display proper error lines so it was a peace of cake finding errors but I can’t imagine what would happen in a larger JS file….

    S.

  35. kingschnullion 27 Mar 2009 at 2:59 pm

    the comma thing was just what i was searching for - thanks for the notes buddy.

  36. Everetton 03 Apr 2009 at 8:24 pm

    I agree with Pete, FF should not be so nice with errors. Of course, IE’s errors are so cryptic it takes a million years to figure out something as simple as a comma. It was in a totally unrelated location.

    Like Franta, I repeat the question: does anyone know how to interpret the line and char numbers IE reports? It’s not line number in the source html or js document. It doesn’t seem to be line number in the script tag either.

    (My ulterior motive to wishing FF was more strict is that I much prefer debugging js in firebug than in IE. I don’t have Visual Studio, nor would it be convenient to purchase.)

  37. nickon 02 Jul 2009 at 2:02 pm

    I have any error in java script on my website home page it says: Object dosent sport this property or method source ( http://www.radissontravels.com/index.html) Line 1404. Any body help me regard this

Trackback URI | Comments RSS

Leave a Reply