+ 1

What is the output of this code and why?

var i=0; for(; i<12 ;){ i+=2; } console. log(i) It's a JavaScript question

29th Jul 2019, 6:23 PM
Francis Woli
Francis Woli - avatar
6 odpowiedzi
+ 3
12. In every cycle, i is incremented by two. Penultimate execution of for, it values 10. Still less than 12, for is executed, i evaluates to 12, condition i<12 is no more satisfied, for stops.
29th Jul 2019, 6:43 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
+ 3
If this is a quiz question then the quiz is screwed up. Until you forgot that it is <= and not just plain <
29th Jul 2019, 10:32 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
Interesting.... Try and console.log() in any cycle
29th Jul 2019, 7:30 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
+ 1
I get 12: var i = 0; for(;i<12;){ i+=2; } console.log(i);
29th Jul 2019, 7:38 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
0
answer is 14, I don't know why?
29th Jul 2019, 7:10 PM
Francis Woli
Francis Woli - avatar
0
Yes, I also got 12 but don't know why
29th Jul 2019, 10:29 PM
Francis Woli
Francis Woli - avatar