DEV Community

Discussion on: Guess the output of this JS code

Collapse
 
abdelrahman_dwedar profile image
‘Abdelraḥman Dwedar 👨🏻‍💻🇵🇸

Nice one!

The solution is:
10
9
8
7
6

The explanation:
1- It'll output 10 since we didn't change it yet.
2- We'll increase i to 1 and num decreased to 9.
3- Increases i to 2 and num decreased to 8.
4- Increases i to 3 and num decreased to 7.
5- Increases i to 4 and num decreased to 6.
Then it ends, 'cause num will be 5 while i will be the equal, so it stops.