By using setTimeout
you allow the page to be interactive before the checkAuth
function completes.
Essentially, you are preventing the checkAuth
from holding up the page.
As a side note, the minimum delay specified in the HTML5 specification is 5ms, so a wait of 1ms will actually be a wait of 5ms. If it is important for you to reclaim that time, you can achieve the same result with a 0ms delay by using window.postMessage
. This was originally designed to handle cross-origin communication, but has a similar effect as setting a timeout with 0ms (which you can't do as browsers only allow 5ms - or 10ms in some older browsers).
Lastly, the timing is not guaranteed. JavaScript runs on a single thread, so when you push something out onto a timer it must wait for an opening in the execution of the rest of the JavaScript before it gets to take its turn on the thread - it doesn't run in parallel.