Is this code looping or recursive?

var timer1 = (cb, time) => {
  (function loop() {
    cb();
    setTimeout(loop, time);
  })();
};

var timer2 = (cb, time) => {
  cb();
  setInterval(cb, time);
};
    Is the
  1. timer1 code looping or recursive?
  2. what"s the difference between timer1 and timer2?
Jul.10,2022

Recursive, indirect.
the difference is that 1 stops when cb throws an exception and 2 doesn't stop.
another difference is that 1 can be transformed into high precision, while 2 depends entirely on the accuracy of the browser itself


  1. from a code point of view, calling yourself is recursive, but with an extra interval
  2. The difference between timer1 and timer2 is actually the difference between setTimeout and setInterval
  3. .
setTimeout()
setTimeout()

setInterval()
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e3436f-437e2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e3436f-437e2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?