Interesting error reporting difference in Chrome and Firefox

This post is more than 2 years old.

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>";
	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>";

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?

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for HERE Technologies. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA