Spot the Variable Mistake
Find the Mistake Easy
Question
This code has an error. What is wrong?
Code
const price = 20;
price = price - 5;
console.log(price);
Hint
The second line tries to change the value of a const variable.
Explanation
const declares a variable that cannot be reassigned. Line 2 (price = price - 5) attempts to reassign price, which throws a TypeError. The fix is to use let price = 20; instead.
Related Resources
Related Lessons
- Variables
Learn how variables work in programming.
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.