+ 2
Why output 5?
for(var i=0;i<3;i++) i+=1; console.log(i%2==0?++i:--i); https://code.sololearn.com/WZpC07eorF3n/?ref=app
6 ответов
+ 5
https://code.sololearn.com/WOMAuWBk40o0/?ref=app
+ 1
Because after the loop in first line the i=4
Then in if (4%2==0) ++i
So i=4
i=4+1
i=5;
+ 1
BaselAl_hajeri['MBH']
Whi after the loop in first line the i=4?
+ 1
Dear Vasiliy :
for(var i=0; i<4; i++)
console.log(i) //0 1 2 3
alert(i) // 4 __ after the loop
for(var i=1; i<4; i++)
console.log(++i) //2 4
alert(i) // 5
0
1. i=4;
2.
3.i=4+1;
4.
5.i=5;
0
I think I understood ☺:
for (var i=0; i<3; i++) i+=1;
👇
1. i=0; true; i+=1; i=1; i++;
2. i=2; true; i+=1; i=3; i++;
3. i=4; false;