A Common Cause of "Uncaught syntax error: unexpected identifier" in JavaScript

If you get the following JavaScript error in your console:

Uncaught SyntaxError: Unexpected identifier

One of the most common reasons is that you’re trying to mutate (change) a const variable. You can’t do that.

In JavaScript, the keyword const is a so-called immutable variable which is used for variables that you don’t want anyone to modify or redeclare.

Use let if you want your variables to be: mutable, changeable, modifiable, updatable (same thing, different words).

Has this been helpful to you?

You can support my work by sharing this article with others, or perhaps buy me a cup of coffee 😊


Share & Discuss on