While studying Async and Performance from "You Don't Know JS" I tried this small code snippet:
var t = [];
var c = 1;
function foo() {
t.push((performance.now()).toString());
if (c < 50) {
setTimeout(foo, 0);
c++;
}
}
For the first few times the browser (I used chrome) took less than 4ms
to call foo
. Later on it took somewhat little more than 4ms
.
.
I wanted to ask, despite being setTimeout()
while creating a task why is it behaving like microtask for the first 3-4 times?
Kindly help me out, Thank You.