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.