Prefix vs Postfix Increment
Multiple Choice Medium
Question
After let x = 5; let y = x++; what are x and y?
Hint
Postfix returns the old value, then increments.
Explanation
x++ (postfix) returns the current value of x (5) and then increments x to 6. So y gets 5 and x becomes 6. With ++x (prefix), x would be incremented first and y would get 6. The difference matters when the increment is used in a larger expression.
Related Resources
Related Lessons
- Numbers and Math
Learn about numbers.
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.