Why does using while loop with a function and without function gives me different result


#1


The while loop prints out 3 hello and a 2, i don't know where does the 2 comes from but when i set a var function for the while, the 2 will disappear.


for ( var counter = 0 ; counter < 3 ; counter++)
{ console.log ( counter)}
var i = 0;

while ( i < 3 ) 
{
    console.log("hello");
    i++
}


#2

Actually, should be:

0
1
2
3 hello

<- 2

Looks like this arrow shows the value returned by the expression or function.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.