'While' Loops in JS help!


#1

there is the loop

var j = 0;
while (j < 5) {    
    console.log(j);
    j++;
};

////
the solution is
0
1
2
3
4
4

why there are two 4?


#2

It has to do with the console/codecademy running a validation on your code. Nothing to worry about


#3

What you see is a feature of the console that echoes the last unused value in your code. You may have seen this in the first exercise before console.log was introduced. So the second 4 comes from j++; . As @stetim94 said that is nothing to worry about and may happen occasionally when the code end with an unused value in the memory. Statement like e.g. console.log that have no value (undefined) don't produce such an echo.