Uncaught SyntaxError: Unexpected var token

I have a Uncaught SyntaxError error: Unexpected var token displayed between (1) and (2), a very strange error, and that makes no sense.

if ($hiddenimage.length==0) { //if this is the first time moving over or clicking on the anchor link var $hiddenimage=$('<img src="'+this.href+'" />').appendTo($hiddenimagediv) //populate hidden div with enlarged image $hiddenimage.bind('loadevt', function(e){ //when enlarged image has fully loaded loadarea.empty().append($.thumbnailviewer2.buildimage($, $anchor, s, options) (1) - var $targetimage=$.thumbnailviewer2.buildimage($, $anchor, s, options) //create reference actual enlarged image (2) - $loadarea.empty().append($targetimage) //show enlarged image $.thumbnailviewer2.showimage($targetimage, s) }) 
+7
source share
2 answers

Count the open parentheses in this line:

 loadarea.empty( ).append($.thumbnailviewer2.buildimage($, $anchor, s, options) ^ ^ ^ ^ ^ 1 0 1 2 1 

Add another closed groove; the parser considers that you are still specifying the arguments to the append() function, and the var keyword is not valid in this context.

Also use semicolons. If not for you, do it for Douglas’s health.

+19
source

I had a similar error message in console with minifier parsing javascript source code. I found that using // comments , as always, interrupted the thumbnail process and gave me an error in the console. So I switched all /* comments */ so. MDN Javascript Comments And right away, everything figured out as expected. Hope this helps.

+1
source

All Articles