0 it no longer meets with the condition so the loop terminates. The program terminates as well.
Consider a terminal and CPU environment. Commands are given at the command line and the CPU executes the command and returns a response. We are working in a console envrionment very similar to this. When we submit our code it is entered at the command line and executed immediately. When it is finished executing the console responds.
When the last command is
console.log() then what it outputs is the final response. When the last command is an assignment (num = num - 1) the response will be the value in the assignment (think of the response as a buffer dump). Hence, since your code ends with an assignment, the value
0 is the response.
We can get around this unexpected output by reversing the order of the lines in your while statement.
num -= 1
Now the 0 won't be displayed.