The timeout doesn’t start counting until after the script has completed, and most browsers don’t do a zero timeout, for performance reasons. You can learn more about this at the Reasons for delays longer than specified section of the setTimeout documentation page.