Browser console output has a mysterious number in for loop with settimeout?

后端 未结 2 442
眼角桃花
眼角桃花 2021-01-16 21:37

Running this on console displays some details right after, followed by the actual console logs. What does those details mean in different browser?

2条回答
  •  被撕碎了的回忆
    2021-01-16 22:10

    Your setTimeout() calls create functions that all reference the exact same variable, that i defined in the for loop. When the loop is finished, the value of i will be 10, so that's what's logged when the timer handlers fire.

提交回复
热议问题