Search for a command to run...
How an interval re-arms, and where a one-shot timer cuts in
The counter starts at zero
n lives in the module scope, so every run of the interval callback reads and writes the same variable.
Execution
1let n = 0;//n: 02 3const id = setInterval(() => {4 n += 1;5 console.log('interval', n);6 7 if (n === 3) {8 clearInterval(id);9 console.log('cleared');10 }11}, 10);12 13setTimeout(() => console.log('timeout at 25ms'), 25);14 15console.log('sync done');