Spot the const Reassignment Error
Find the Mistake Easy
Question
This code throws an error. What is wrong?
Code
const items = [1, 2, 3];
items = [4, 5, 6];
console.log(items);
Hint
const prevents reassignment of the binding, though the array contents can still change.
Explanation
The variable items is declared with const, which means the binding cannot be reassigned. items = [4, 5, 6] throws a TypeError. Note that items.push(4) would work — const prevents reassignment of the variable, not mutation of the value it holds.
Related Resources
Related Lessons
- JavaScript Variables
Learn about const semantics.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.