I have a few questions about the following code that I ran in Chrome's console (I highlighted the difference between each loop). The intent of the code is to print out even numbers immediately, and then print out the odd numbers in order (because the stack is clear, and Chrome starts running through the event queue, from what I understand).
For the first loop, why does it show
undefined
? Why is there the little<·
on the left ofundefined
?For the second loop, why does
1
print where it does? It looks like this is something the console is doing, not my code.For the second loop, why does
2
print out? The for loop is for strictly less than 2.Why does the third loop print
undefined
and3
? What's different that the console didn't actually print out a number next to the<·
symbol?For the last loop, why didn't
1
and3
print? Kind of seems like it printed4
3 times.How do you accomplish the intent of my code using setTimeout in this way?
If you try the code yourself, it seems like the number next to <·
increments each time you run the loop.