Why does the last shows 5?


// Write your code below!
for (var i=0;i<5;i++)


var i=1;
while(i <=5)


it shows 5 because of your condition

while(i <=5);

your loop will not terminate when i gets to 5 because i can be 5 that's why it prints it


Afaik every value is buffered until it is either used or replaced by the next and if a value is still in the buffer when the program ends it is echoed on the console. Which should not be confused with a console.log output and the test functions that looks for console.log outputs will not detect it. Also this works only for the last value (the others would have been replaced) and it doesn't work for undefined. So what you see is the value of this statement: