Question on Javascript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Question on Javascript

What is the output of this code? var x = 0; while(x<6) { x++; } document.write(x);

21st Feb 2018, 9:35 PM
Shittu Adams
Shittu Adams - avatar
2 Answers
+ 12
6
21st Feb 2018, 9:39 PM
Vukan
Vukan - avatar
+ 3
As Vukan said, it'll be 6. Your condition stops the loop if it's 6 or greater. The statement inside of your loop is only increasing X by one, thus the moment it becomes 6 the loop isn't going to run again, leaving X with a value of 6.
21st Feb 2018, 9:45 PM
Fata1 Err0r
Fata1 Err0r - avatar