Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SyntaxError: missing ; before statement

I am getting this error :

SyntaxError: missing ; before statement

Why would I get that from this code? How can I get around this ?

var $this = $("input");
foob_name = $this.attr('name').replace(/\[(\d+)\]/, function($0, $1) {
   return '[' + (+$1 + 1) + ']';
}));
like image 280
Trip Avatar asked Feb 09 '11 00:02

Trip


People also ask

How do you fix missing before statement?

The JavaScript exception "missing ; before statement" occurs when there is a semicolon ( ; ) missing somewhere and can't be added by automatic semicolon insertion (ASI). You need to provide a semicolon, so that JavaScript can parse the source code correctly.

What type of error is a missing semicolon?

The Missing Semicolon Before Statement error is a specific type of SyntaxError object.

Does JavaScript use semicolon?

Semicolons are an essential part of JavaScript code. They are read and used by the compiler to distinguish between separate statements so that statements do not leak into other parts of the code. The good news is that JavaScript includes an automatic semicolon feature.


1 Answers

Looks like you have an extra parenthesis.

The following portion is parsed as an assignment so the interpreter/compiler will look for a semi-colon or attempt to insert one if certain conditions are met.

foob_name = $this.attr('name').replace(/\[(\d+)\]/, function($0, $1) {
   return '[' + (+$1 + 1) + ']';
})
like image 123
ChaosPandion Avatar answered Sep 20 '22 17:09

ChaosPandion