+ 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

7th May 2019, 8:24 PM
Solo
Solo - avatar
6 ответов
+ 5
https://code.sololearn.com/WOMAuWBk40o0/?ref=app
7th May 2019, 11:31 PM
ODLNT
ODLNT - avatar
+ 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;
7th May 2019, 8:27 PM
Basel.Al_hajeri?.MBH()
Basel.Al_hajeri?.MBH() - avatar
+ 1
‎BaselAl_hajeri['MBH'] Whi after the loop in first line the i=4?
7th May 2019, 8:37 PM
Solo
Solo - avatar
+ 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
7th May 2019, 8:53 PM
Basel.Al_hajeri?.MBH()
Basel.Al_hajeri?.MBH() - avatar
0
1. i=4; 2. 3.i=4+1; 4. 5.i=5;
7th May 2019, 8:28 PM
Basel.Al_hajeri?.MBH()
Basel.Al_hajeri?.MBH() - avatar
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;
7th May 2019, 9:22 PM
Solo
Solo - avatar