简体   繁体   English

语法错误:缺少; 声明前

[英]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) + ']';
}));

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) + ']';
})

太多)括号删除其中之一。

Or you might have something like this (redeclaring a variable):或者你可能有这样的事情(重新声明一个变量):

var data = [];
var data = 

I got this error, hope this will help someone:我收到此错误,希望这对某人有所帮助:

const firstName = 'Joe';
const lastName = 'Blogs';
const wholeName = firstName + ' ' lastName + '.';

The problem was that I was missing a plus (+) between the empty space and lastName.问题是我在空格和姓氏之间缺少一个加号 (+)。 This is a super simplified example: I was concatenating about 9 different parts so it was hard to spot the error.这是一个超级简单的例子:我连接了大约 9 个不同的部分,所以很难发现错误。

Summa summarum: if you get "SyntaxError: missing ; before statement", don't look at what is wrong with the the semicolon (;) symbols in your code, look for an error in syntax on that line. Summa summarum:如果您收到“SyntaxError: missing ; before statement”,请不要查看代码中的分号 (;) 符号有什么问题,在该行查找语法错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM