This question already has an answer here:
- javascript i++ vs ++i 8 answers
I wonder why in this code counter is not saving after it is incremented? I mean now the behavior is the same as if I used if (counter+1 % 2). But ++ operator supposed to permanently increment the variable.
let counter=0;
for (let i = 0; i < 10; i++) {
console.log(counter,'every')
if (counter++ % 2) console.log(counter,'odd');
}
Aucun commentaire:
Enregistrer un commentaire