Bastiaan Zwanenburg
Bastiaan Zwanenburg

Reputation: 143

JS error: SyntaxError: missing ; before statement

I'm getting an error (it's javascript btw), and even after a lot of googling, I cannot find where it comes from. It says "SyntaxError: missing ; before statement", with an arrow pointing to the point in between nmwoo_vars and file_meta. Anyone who knows how to solve it?

var nmwoo_vars.file_meta = [{"label":"Graveren","type":"checkbox","options":"Ja, graveer mijn bril","price":"10"},{"label":"Gravering","type":"text","options":"","price":""}];

Upvotes: 0

Views: 504

Answers (2)

QIKHAN
QIKHAN

Reputation: 274

Here is a sample code to test your object creation, it works fine.

var nmwoo_vars = new Object();
nmwoo_vars.file_meta = [{"label":"Graveren","type":"checkbox","options":"Ja, graveer mijn    bril","price":"10"},{"label":"Gravering","type":"text","options":"","price":""}];

alert(nmwoo_vars.file_meta[0].label);

As Pointy mentioned you cannot initialize the object on the fly. You must create the object first and then assign its properties.

Upvotes: 0

Pointy
Pointy

Reputation: 413709

A var keyword is used to declare variables. You're just adding a property to an object, so var is incorrect.

nmwoo_vars.file_meta = [{"label":"Graveren","type":"checkbox","options":"Ja, graveer mijn bril","price":"10"},{"label":"Gravering","type":"text","options":"","price":""}];

is all you need (assuming "nmwoo_vars" is itself a variable that references an object).

Parsers aren't very smart, in most cases. The error you got means that the parser made an assumption about what your code is trying to do. In real life those assumptions are wrong probably more often than they're right, so such messages don't help much, and are especially baffling to those learning the language. Usually it's a good idea to just examine your code and verify to yourself that it's syntactically correct, ignoring the specifics of the error.

Upvotes: 2

Related Questions