What is the difference between those two, and when will I use one over the other?
To understand them deeply please once go through the event loop phases.
SetImmediate: It gets executed in the "check" phase. The check phase is called after the I/O phase.
SetTimeOut: It gets executed in the "timer" phase. The timer phase is the first phase but is called after the I/O phase as well as the Check phase.
To get the output in a deterministic manner, it will depend on which phase the event-loop is; accordingly, we can use the function out of two.