JavaScript: Repeat a function X times at I intervals
I don't see anything problematic with your code, but just for fun, here are some alternative approaches to various parts of the code. It's 100% DRY, and functionally identical to the original.

function repeatXI(callback, interval, repeats, immediate) {
  var timer, trigger;
  trigger = function () {
    callback();
    --repeats || clearInterval(timer);
  };

  interval = interval &lt;= 0 ? 1000 : interval; // default: 1000ms
  repeats  = parseInt(repeats, 10) || 0;      // default: repeat forever
  timer    = setInterval(trigger, interval);

  if( !!immediate ) { // Coerce boolean
    trigger();
  }
}


And here's a jsfiddle demo

If you want, you can return timer from the function (as I do in the demo), so you can clear it (i.e. cancel the repeater) elsewhere in your code.

Regardless of the implementation-specifics it's worth noting that timers are unreliable at the best of times (since JS is single-threaded). Depending on your needs it may not be a good idea to set n timeouts at n * interval as you do for finite repeats. If a few of the timeouts get blocked long enough, they'll all queue up, and fire at once, once the thread clears. With setInterval though, you're guaranteed that there'll be at least interval time between the callbacks.

So it depends on your needs how you want to implement it.