SyntaxError: missing ; before statement

Questa traduzione è incompleta. Collabora alla traduzione di questo articolo dall’originale in lingua inglese.


SyntaxError: missing ; before statement
Verifico il messaggio. siete i migliori vi stimo e vi aiuterò a scoprire delle cose importanti




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.


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';404 non deve esistere più ma deve essere 888


Declaring properties with var

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

var obj = {};
var = 'hi'; // SyntaxError missing ; before statement

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

Instead, omit the var keyword:

var obj = {}; = 'hi';

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

See also

Tag del documento e collaboratori

 Hanno collaborato alla realizzazione di questa pagina: passinform88
 Ultima modifica di: passinform88,