Ok, perhaps "interesting" is a bit of a stretch, but as I'm doing some work while waiting for new tires to be put on my car, my base level for "interesting" is a bit lower than normal. I'm testing some code that I wrote in a Powerpoint slide - code I was sure worked fine but I wanted to be really sure, and I found that I had a typo. Consider the snippet below - you will probably see it right away.
$.getJSON("/data.json", function(res) {
var s = "<ul>";
//["ray","jeanne","jacob","lynn","noah","maisie"]
for(var i=0;i<res.length;i++) {
if(res[i].length < 4) {
s+="<li class=\"short\">"+res[i] + "</li>");
} else {
s+="<li>"+res[i] + "</li>");
}
}
s += "</ul>";
$("#someDiv").html(s);
});
When I ran this in Firefox, I got: SyntaxError: missing ; before statement test1.html:22
.
Line 22 is the line that adds the li with class short to the variable s. I looked at it and couldn't quite figure out what was wrong.
I then switched to Chrome and got this error: Uncaught SyntaxError: Unexpected token )
Now - that made sense! I immediately saw the extra ) I had at the end of my line. (I also had it two lines later.)
But what I found interesting is how different the errors were. Both were syntax errors, but the actual detail was quite different. Anyone have an idea as to why this is?
Archived Comments
because parsers. Everyone has their own parser. Some parsers have better error messages than others.
Safari used to use a parser built with bison, which could only ever report "syntax error" with the line number, but never more specific than that. They are using a better parser now, and get better error messages. But back then ... sheesh!
I get that some parsers will have "better" error messages, but these two messages seem almost contradictory. It is just plain weird. :)
The first line of code that sets the variable "s" with the odd line break between the quotes may play into it.
That's just a bad paste - fixing now.
Fixed - thanks Joel.