Tell us what’s happening:
Describe your issue in detail here.
See code below. myVar++ evaluates at 88, which makes sense.
If everything to the “right” of the equal sign is evaluated first, why does myVar = myVar++ evaluate as 87, when using the Post Fix increment operator? Shouldn’t it evaluate as 88?
Your code so far
let myVar = 87;
myVar = myVar++; // Evaluates as 87
myVar++; // Evaluates at 88
Your browser information:
Chrome
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36
bbsmooth, I get the difference between Pre and Post. I just don’t understand why using the assignment operator with increment results in a 87, whereas when you leave out the assignment operator, and just use the variable + increment operator you get 88. Thanks for the reply!
… Because of the difference between pre and post incrementing.
The incrementing operator is a function with a return value. Everything’s a function, operators are just a little less clear about the fact that they are functions.
The return value depends upon if pre or post incrementing is used.