why ? 12 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

why ? 12

What is the output of this code? var a = 0; for(k = 1; k <= 2; k++) {} for(i = 0; i <= 5; i++) {} a++; console.log(a); answer 12

25th Aug 2018, 1:10 AM
Алмат Айтбаев
Алмат Айтбаев - avatar
5 Answers
+ 5
It's because of the nested for loops the for(i) loop will be looped 2 times for (k.......){ //this will be looped the amount of times k will be looped (2) for(i.....){ //this will be looped the mount of times i will be looped(6) times the amount that k will be looped (2) 6*2=12 a++; } }
25th Aug 2018, 2:25 AM
Roel
Roel - avatar
+ 5
thank you I understood it
25th Aug 2018, 2:45 AM
Алмат Айтбаев
Алмат Айтбаев - avatar
+ 3
I do not know. but the answer was written like this.
25th Aug 2018, 1:27 AM
Алмат Айтбаев
Алмат Айтбаев - avatar
+ 3
Jay Matthews here there is no multiplication operator ×
25th Aug 2018, 1:44 AM
Алмат Айтбаев
Алмат Айтбаев - avatar
+ 2
Jay Matthews Would you please explain it more? :(
25th Aug 2018, 1:31 AM
jamilxt
jamilxt - avatar