TypeError const 🟨 JavaScript

TypeError: Assignment to constant variable.

Code reassigned a variable declared with const.

Seen on: JavaScript

Meaning

const prevents reassignment (mutating an object’s properties is still allowed). Use let if the variable must change.

Common causes

  • Reassigning a const in a loop or later code
  • Incrementing a const counter
  • Reassigning an imported binding

⚡ Quick fix

  1. Use let for variables that change
  2. Mutate properties instead of reassigning objects
  3. Create a new variable for the new value

Detailed fix by platform

JavaScript

  1. javascript
    let total = 0;
    for (const n of nums) total += n;

How to diagnose

  1. Declaration — Where is it declared?
  2. Reassignment — Which line changes it?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.