Lets consider a code snippet that sends all mouse movements to a server every 10 seconds.
sendMouseMovements(mouseLocations) gets executed and sends pending values to the server but before clearing the queue
queue =  it gets pre-empted to process mousemove event i.e.
queue.push("X:" + e.clientX + " Y:" + e.clientY). Now a new value is inserted to the queue which isn’t yet sent to server. The previous event resumes from line
queue =  and clears the queue including the newly inserted value which wasn’t processed. That’s a race condition, right?
The way Event Loop works, provides us the Run-to-Completion feature. It guarantees you that whenever a code runs, it cannot be pre-empted and runs to completion before any other code runs. So, in case of the above example, the pre-emption at line
queue =  is never going to happen, hence the race condition won’t occur, ever.
Confused? Here’s an interesting example:
Keep printing “Still running…” for 1 second and then stop. Simple? … Guess what? It’s a never-ending loop. Try it yourself in the console or check the jsfiddle (Warning: It may hang or crash your browser)
So, what’s happening here? The timer will be scheduled to trigger after 1 second but a code is already running i.e. the while loop. It’ll wait for it to Run-to-Completion. But the loop is only going to stop if the timer callback gets executed and the timer will only fire when loop gets completed. See what the Run-to-Completion feature did there?