function timeout0() { console.log('timeout 0'); } function immediate() { console.log('immediate'); } setTimeout(timeout0, 0); setImmediate(immediate); If you execute this code 10 times, then you can see that the order of the functions is different, sometimes the timeout is 0, and sometimes the timeout occurs first. Why is that?