r/learnjavascript • u/grave4us • Apr 10 '26
Increment/decrement trouble
I don't quite understand how increment and decrement operators work—specifically, under what conditions switching between postfix and prefix forms alters or returns the value, and in which cases they behave identically.
(im using the google translator, if anything is unclear, please ask for clarification.) Thank you!
5
Upvotes
View all comments
-3
u/ashkanahmadi Apr 10 '26
It's easy. Incrementing means "increase by one". When you increment a variable, you say "whatever the value is, add one to it". For example,
x++is the short version ofx = x + 1which says "whateverxis, add one to it".For example:
You can do it like this too:
The decrement is exactly the same concept but instead of adding 1, you take out 1. The rest is the same.