How the Result is 120 ??? And why curly braces empty here??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How the Result is 120 ??? And why curly braces empty here???

var x=1; for(x; x<10;x++){} x+=x+100; document.write(x); //Ans: 120

3rd Jan 2023, 11:09 AM
Mohammad Tausiful Alam
Mohammad Tausiful Alam - avatar
2 Answers
+ 1
Because in the for loop you increment x 9 times, so x = 10 after the loop. In the for loop, you do nothing except increment x 9 times. x += x(which is 10 now) + 100 So x += 110 x = 120
3rd Jan 2023, 11:17 AM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
0
Thanks
3rd Jan 2023, 11:28 AM
Mohammad Tausiful Alam
Mohammad Tausiful Alam - avatar