Lingua-e
← Errors
JavaScript

Identifier Already Declared: What It Means and How to Fix It

Error reference

Identifier Already Declared

Language

JavaScript

Severity

Medium

When it happens

This SyntaxError is thrown when let or const is used to declare a variable name that already exists in the same scope.

Potential fixes

To update an existing variable, use assignment (=) without a declaration keyword. If you need a new variable in a nested scope, wrap it in a block ({}). Rename one of the conflicting variables if they serve different purposes.

Deep dive

This SyntaxError is thrown when let or const is used to declare a variable name that already exists in the same scope. Unlike var, which silently allows redeclaration, let and const enforce unique names within a block scope.

Why it happens

  • Declaring the same variable twice with let or const in the same block.
  • A variable name collides with a function parameter in the same scope.
  • Copy-pasting code that introduces a duplicate declaration.
  • Bundling or transpilation that puts two modules' variable names in the same scope.

Potential fixes

To update an existing variable, use assignment (=) without a declaration keyword. If you need a new variable in a nested scope, wrap it in a block ({}). Rename one of the conflicting variables if they serve different purposes.

Examples

JavaScript

Code that triggers the error

let count = 0;
let count = 1; // redeclaration in same scope

Error output

SyntaxError: Identifier 'count' has already been declared

Fixed code

let count = 0;
count = 1; // reassign, not redeclare

Practice in English

How would you explain an Identifier Already Declared to a fellow dev? Choose the right phrase:

"I hit an error...

Ready to practice your English at work?

Lingua-e has interactive exercises built around real developer conversations: standups, code reviews, retrospectives, and more. Practice until it comes naturally.

Try Lingua-e for free