mardi 24 octobre 2017

Javascript unsure about s+=1 - Why it alerts 5 not 1, as what is s equal to in the s=s+1

I'm not sure how the s+=1 works, i know it's s=s+1, but am unsure work it alerts 5 as i assumed it would be 1. Thanks

var s=0;

for(i=0;i<=8;i++)

if((i%2)==0)s+=1;

alert(s);

Aucun commentaire:

Enregistrer un commentaire