+ 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
6 Réponses
+ 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++;
}
}
+ 5
thank you I understood it
+ 3
I do not know. but the answer was written like this.
+ 3
Jay Matthews here there is no multiplication operator ×
+ 2
Jay Matthews Would you please explain it more? :(