I came across a function where it had a setTimeout
inside with a timeout growing exponentially (timeout *= 2)
.
let timeout = 10000
fun
This is not a recursive function call. The call to setTimeout
will cause foo
to be called by the JavaScript event loop at a later time.
This code will not cause a stack overflow or any such problems. It should be completely safe.
To understand how this works in-depth, I suggest reading up on the JS event loop and microtasks.