+ 2

js problem

why it result 11 Explain this code! var num= 1; for(; num <6 ;num+=2){ num =num* num } console.log(num) //how result is 11

3rd Jun 2019, 4:42 PM
Danielov
Danielov - avatar
1 Answer
+ 4
Before loop: num = 1 ** Begin loop Iteration 1 (num = 1) Is num < 6 // yes num = 1 * 1 // 1 num = 1 + 2 // 3 Iteration 2 (num = 3) Is num < 6 // yes num = 3 * 3 // 9 num = 9 + 2 // 11 Iteration 3 (num = 11) Is num < 6 // no ** Loop ends num value is now 11, log it in JS console. Hth, cmiiw
3rd Jun 2019, 5:20 PM
Ipang