Running this on console displays some details right after, followed by the actual console logs. What does those details mean in different browser?
You're scheduling 10 console.log
statements at the end of the call stack (when the function returns after the for loop has completed). Since i
is 10
at this point, it prints 10
as many times as you've called setTimeout
with that handler.
EDIT
Upon clarification of the question, what you are seeing is the value of the last expression evaluated. In this case it is the value of the last timeout you had set. window.setTimeout
returns an ID that is cancellable and unique for the tab session. In this case, it seems like the browsers are incrementing a count they already had stored, so you're getting increments of 10 because you're calling setTimeout
10 times in the loop.