Javascript 语法错误:缺少;声明前
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4940033/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SyntaxError: missing ; before statement
提问by Trip
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(foob_name = $this.attr('name').replace(/\[(\d+)\]/, function(var data = [];
var data =
, ) {
return '[' + (+ + 1) + ']';
})
, ) {
return '[' + (+ + 1) + ']';
}));
回答by ChaosPandion
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.
以下部分被解析为赋值,因此解释器/编译器将查找分号或在满足某些条件时尝试插入分号。
const firstName = 'Joe';
const lastName = 'Blogs';
const wholeName = firstName + ' ' lastName + '.';
回答by Dustin Davis
too many ) parenthesis remove one of them.
太多)括号删除其中之一。
回答by Kovács Imre
Or you might have something like this (redeclaring a variable):
或者你可能有这样的事情(重新声明一个变量):
##代码##回答by Juuso Nyk?nen
I got this error, hope this will help someone:
我收到此错误,希望这对某人有所帮助:
##代码##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”,请不要查看代码中的分号 (;) 符号有什么问题,在该行查找语法错误。