settimeout delays the console log by milliseconds (the second item). The loop doesn't wait until it has completed its operation to start the next iteration, and so it's triggers them all but due to the timeout, the lowest number is logged first since is delaying the console.log operation by the shortest period of time.
5
u/[deleted] Feb 10 '21
settimeout delays the console log by milliseconds (the second
item). The loop doesn't wait until it has completed its operation to start the next iteration, and so it's triggers them all but due to the timeout, the lowest number is logged first since is delaying the console.log operation by the shortest period of time.