+ 3

Why does the code below output 6?

var x=0; while(x<6){ x++; } document.write(x);

25th Jun 2019, 11:10 PM
takeru
takeru - avatar
2 Réponses
+ 6
when x == 5 loop still executes as 5 is smaller than 6 then x becomes 6, loop terminates then as 6 is not smaller than 6 so final value of x after loop is 6
26th Jun 2019, 12:10 AM
Mind To Machine 💻🕆
Mind To Machine 💻🕆 - avatar
+ 2
thanks!
26th Jun 2019, 3:49 AM
takeru
takeru - avatar