When there's an interval method running the background, can it cause the current function to stop in the middle, go do the interval method and then return to the current function?
No, it's not possible. The interval is added to the events loop (queue) and new item from this event queue is only picked up when the call stack is empty. This means that the
foo should finish executing before new item is processed from the queue. Moreover, it's not only functions added through interval won't get executed until
foo is finished, it's all other things like UI events and network request callbacks.
Here is a good talk that explains what this queue is.