Why this code outputs 3, not 2?
var i = 1;
i = ++i + --i;
console.log(i);
I expected:
++i // i == 2
--i // i == 1
i = 1 + 1 // i == 2
Where I made mistake?
The changes occur in this order:
i
(to 2)i
for the left hand side of the addition (2)i
(to 1)i
for the right hand side of the addition (1)i
(3)… and seeing you attempt to do this gives me some insight in to why JSLint doesn't like ++
and --
.