"Identifier has already been declared" in JavaScript — What It Means and How to Fix It

What the JavaScript error "Identifier has already been declared" means and how to fix it.

Published October 30, 2026

You declared the same name twice with let, const or class in the same scope, which is not allowed.

What it means and why it happens

Typical causes: copy-pasting code, redeclaring in scripts loaded twice or mixing var and let for the same name.

Read the full message: it names the file and line where the problem was detected, which is the best place to start.

What you see

run the code
SyntaxError: Identifier 'count' has already been declared

Practical examples

Code that triggers it

let count = 1
let count = 2

The fix

let count = 1
count = 2   // reassign instead

Scope with blocks

{ let temp = 1 }
{ let temp = 2 }   // fine: separate blocks

Common mistakes

  • Loading a script twice.
  • Declaring in global scope across files.
  • Mixing var and let.

Key takeaways

  • SyntaxError: Identifier has already been declared: You declared the same name twice with let, const or class in the same scope, which is not allowed.
  • Read the message and the line number first.
  • Fix the cause, don't just silence the error.

FAQ

var allows redeclaration?

Yes, but it causes bugs; prefer let/const.

How do I find which line caused SyntaxError: Identifier has already been declared?

The error message and stack trace show the file and line; start there and work backwards.

More JavaScript articles