Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught SyntaxError: Unexpected token var

I have an error Uncaught SyntaxError: Unexpected token var displayed between (1) and (2) its a very odd error and it doesn't make sense at all.

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)
    })
like image 229
Bob R Avatar asked Dec 30 '10 07:12

Bob R


2 Answers

Count the open parentheses on this line:

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

Add another closing paren; the parser thinks you're still specifying arguments to the append() function, and the var keyword is invalid in this context.

Also, use semicolons. If not for your sake, do it for Douglas' health.

like image 24
cdhowie Avatar answered Oct 21 '22 17:10

cdhowie


I had a similar error message in the console with the minifier parsing my javascript source code. I found that using // comments like so always interrupted the minification process, and gave me an error in the console. Therefore i switched all /* comments */ like so. MDN Javascript Comments And immediately everything parsed as expected. Hope it helps.

like image 91
mangrove108 Avatar answered Oct 21 '22 18:10

mangrove108