Why does the last shows 5?


#1

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

console.log(i+1+".hello,world");

}
var i=1;
do{
console.log(i+".hahahahaha");
i++;
}
while(i <=5)


#2

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


#3

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:

i++;