We're looking for a person or people to help audit MDN to find places we could speed up. Is this you or someone you know? Check out the RFP: https://mzl.la/2IHcMiE

Unsere Freiwilligen haben diesen Artikel noch nicht in Deutsch übersetzt. Machen Sie mit und helfen Sie, das zu erledigen!
Sie können den Artikel auch auf English (US) lesen.


SyntaxError: missing variable name (Firefox)
SyntaxError: Unexpected token = (Chrome)

Error type


What went wrong?

A variable is missing a name. This is likely due to a syntax error in your code. Probably a comma is wrong somewhere or you struggled with coming up with a name. Totally understandable! Naming things is so hard.


Missing a variable name

var = "foo";

It's tough coming up with good variable names. We all have been there.

var ohGodWhy = "foo";

Reserved keywords can't be variable names

There are a few variable names that are reserverd keywords. You can't use these. Sorry :(

var debugger = "whoop";
// SyntaxError: missing variable name

Declaring multiple variables

Pay special attention to commas when declaring multiple variables. Is there an excess comma? Did you accidentally add commas instead of semicolons?

var x, y = "foo",
var x, = "foo"

var first = document.getElementById('one'),
var second = document.getElementById('two'),

// SyntaxError: missing variable name

The fixed version:

var x, y = "foo";
var x = "foo";

var first = document.getElementById('one');
var second = document.getElementById('two');


Array literals in JavaScript need square brackets around the values. This won't work:

var arr = 1,2,3,4,5;
// SyntaxError: missing variable name

This would be correct:

var arr = [1,2,3,4,5];

See also

Schlagwörter des Dokuments und Mitwirkende

 Mitwirkende an dieser Seite: fscholz
 Zuletzt aktualisiert von: fscholz,