Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

SyntaxError: missing ; before statement

이 문서는 아직 자원 봉사자들이 한국어로 번역하지 않았습니다. 함께 해서 번역을 마치도록 도와 주세요!

Message

SyntaxError: missing ; before statement

Error type

SyntaxError.

What went wrong?

There is a semicolon (;) missing somewhere. JavaScript statements must be terminated with semicolons. Some of them are affected by automatic semicolon insertion (ASI), but in this case you need to provide a semicolon, so that JavaScript can parse the source code correctly.

However, oftentimes, this error is only a consequence of another error, like not escaping strings properly, or using var wrongly. You might also have too many parenthesis somewhere. Carefully check the syntax when this error is thrown.

Examples

Unescaped strings

This error can occur easily when not escaping strings properly and the JavaScript engine is expecting the end of your string already. For example:

var foo = 'Tom's bar';
// SyntaxError: missing ; before statement

You can use double quotes, or escape the apostrophe:

var foo = "Tom's bar";
var foo = 'Tom\'s bar';

Declaring properties with var

You cannot declare properties of an object or array with a var declaration.

var obj = {};
var obj.foo = "hi"; // SyntaxError missing ; before statement

var array = [];
var array[0] = "there"; // SyntaxError missing ; before statement

Instead, omit the var keyword:

var obj = {};
obj.foo = "hi";

var array = [];
array[0] = "there";

See also

문서 태그 및 공헌자

 이 페이지의 공헌자: jwhitlock, fscholz
 최종 변경: jwhitlock,