"Assignment to constant variable" in JavaScript — What It Means and How to Fix It
What the JavaScript error "Assignment to constant variable" means and how to fix it.
Published October 30, 2026
"Assignment to constant variable" is occurs when code tries to reassign a variable declared with const.
Key points
- Check the browser console's stack trace to find exactly which line and call triggered the error
Example
const x = 1;
x = 2; // TypeError: Assignment to constant variable.