
You can schedule a function of code to run 5 seconds from now, but you have to put the code that you want to run later into a function and the rest of your code after that function will continue to run immediately. Many workarounds are there to try to implement such functions. You should not just try to pause 5 seconds in javascript. I understand that using setTimeout() involves more thought than a desirable sleep() function, but unfortunately the later doesn't exist. Var y = null // To keep under proper scope You use setTimeout() to rewrite it this way: var x = 1 Place mysterious code that blocks the thread for 100 ms.

It's not that hard to use actually, instead of writing this: var x = 1 The JavaScript setTimeout() method is a built-in method that allows you to time the execution of a certain function.

Unfortunately, setTimeout() is the only reliable way (not the only way, but the only reliable way) to pause the execution of the script without blocking the UI.
