Variable Reassignment
Predict Output Beginner
Question
What does this code print?
Code
let x = 10;
x = x + 5;
console.log(x);
Hint
x starts at 10, then 5 is added.
Explanation
x is initialized to 10. The statement x = x + 5 reads the current value (10), adds 5, and assigns 15 back to x. console.log(x) prints 15. This shows that let allows reassignment, unlike const.
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.