What is the output of this code? for (var i = 5; i <9; i++) {document.write (9-i);} | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

What is the output of this code? for (var i = 5; i <9; i++) {document.write (9-i);}

I got the output 4321. How is it possible? for (var i = 5; i <9; i++) {document. write (9-i);} ¿

12th Aug 2017, 12:24 PM
Tahir Usman
Tahir Usman - avatar
2 Answers
+ 13
i starts at 5 and ends with 8 (<9), so 9-5 = 4 9-6 = 3 9-7 = 2 9-8 = 1
12th Aug 2017, 12:31 PM
Hatsy Rei
Hatsy Rei - avatar
+ 6
< terminates the loop when var reaches a value just less than specified. <= alliws dor the option to use the limit value. Basically, school math
12th Aug 2017, 12:35 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar