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
- Use let for variables that change
- Mutate properties instead of reassigning objects
- Create a new variable for the new value
Detailed fix by platform
JavaScript
- javascript
let total = 0; for (const n of nums) total += n;
How to diagnose
- Declaration — Where is it declared?
- 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026