(I’m assuming the old value of i
is not needed, so i++
and ++i
should at most affect performance.)
Then thing is, I’ve seen a counter incremented like this in code
i++;
and it left me wondering: should I suggest to write ++i;
because given the semantics of pre-increment and post-increment there’s no reason to believe that ++i
could ever be slower than i++
, whereas there is a little chance that i++
is indeed slower?
My double stems from what I know of C++, and which mostly applies for non-builtin types (see here).
But I don’t know enough of JavaScript.
As state above, exactly because I don’t know the answer as whether i++
is slower than ++i
or not, I’d write ++i
because I assume it can’t be slower than i++
(otherwise what starnge language would JavaScript be?).