title: setTimeout vs setInterval - best practices on use
body: <p>I understand the differences between setTimeout and setInterval, as <a href="https://stackoverflow.com/questions/2696692/setinterval-vs-settimeout">this</a> explained it quite nicely.</p>
  
  <p>This question is about best practice when using timers, specifically setTimeout vs setInterval.</p>
  
  <p>If I need to call a countdown several times in a game fairly frequently (for example, a player moves to a new location, which triggers a new countdown which will encourage them to move in <strong>5 seconds</strong>), but it's not necessarily uniform intervals (meaning, they should move to next location, but can hang out at current location and be penalized), is it better performance-wise, and clean code-wise to:</p>
  
  <p>a) keep clearing and setting <code>setTimeout()</code> when the player decides to change location</p>
  
  <pre><code>if (player.newLocation !== player.oldLocation) { //player location has changed
          window.clearTimeout(myTimer);
          myTimer = setTimeout(function() { 
              do something
          },50);  
  } 
  </code></pre>
  
  <p>b) keep setInterval running, but change a variable that acts as that countdown each time the player moves to a new location</p>
  
  <pre><code>var counter = 0;
  if (player.newLocation !== player.oldLocation) {
      counter = 100;
  }
  
  myTimer = setInterval(function() { 
      if (counter &gt; 0) {
            // do something...
            counter--;
      }
  },50);  
  </code></pre>