views:

414

answers:

4

I'm receiving a script error in IE:

Line: 59 Char: 71 Error: Expected identifier, string, or number Code: 0

Line 59, character 71 don't seem to actually correspond to my code. It doesn't even say what file, but I've looked at my main javascript file, viewing the page source, etc.

This has happened to me before and I've looked around until I finally find an error with the code -- usually a comma -- but I would really like to get some use out of these line/char numbers. I read once that it's a reference to the internal version of the page that IE reads from.

Does anyone have information on how to find out what these numbers actually mean and see the line of code that's causing the problem?

Appreciate any help!

+5  A: 

I've found IE Line # / Char #'s to be useless or more hassle then it's worth.

If you're including multiple javascript files and all it gives you is a line # and char # it's alot of work to concatenate all the scripts together to figure it out where the error is.

If I can find the error in firefox using firebug then that's the easiest way. If it's an IE only problem what I do is enable script debugging in Internet Options,

  1. Go to Tools->Internet Options…->Advanced->Disable Script Debugging (Internet Explorer)
  2. Go to Tools->Internet Options…->Advanced->Disable Script Debugging (Other)

    then attach Visual Studio Debugger when an error occurs.

If you're using IE 8, install the developer toolbar because it has a built in debugger.

If you are really keen on not using a debugger and just viewing the source and getting the line # you can try View -> Original Source in the IE Developper toolbar.

In your case you gotta watch out for trailing comma's in object literals

var obj = { 
a: 1, 
b: 2,
}

Or naming a variable with a reserved keyword like "class", that has burned me many times. Here is a list of reserved keywords

Ryu
Thanks for the good tips on the Disable Script Debugging on IE. Firebug in FF is great, but I always find it frustrating to work with IE only bugs. So in theory, concatenating the javascript files together (in the order they're added in the head section of the html) would render a useable line number in IE?
Nathan
A: 

Browsers differ in their determination of the line number and thus do not reliably report the correct line number that an error occurred at in relation to the source code. Internet Explorer, for instance, reports the line number in relation to the browser's own internal rendering of the document source, which may or may not match the source file. Firefox reports the location of the error more reliably, reporting the script file that an error occurred in where applicable.

Line numbers can help you pinpoint the general place in the script where things went awry. You can copy the document source and paste it into a text editor that provides line numbering, such as Textpad. Alternatively, you can set the default HTML Editor on the Programs tab of the Internet Options dialog

Lonzo
"Browsers do not reliably report the correct line." namely Internet Explorer.
recursive
A: 

I would recommend trying out the same page in IE8, if you haven't done so already. If the error doesn't happen, try switching IE8 to Compatibility View.

If you do get the error to occur, then the built-in Developer Tools are very good at finding exactly where the problems in the Javascript occur.

Coxy
A: 

Why, use IE7 or IE8 with the web developer tools on. And when you have a JS bug it will ask you if you want to debug this, you will say "yes, I want" and it will open a nice debugger, exactly on the problematic line.
Sadly, I am on Linux, and cant give you a print screen to show you how to turn this on.

Itay Moav