title: How to kill a javascript setTimeout loop
body: <p>I have this loop that works okay:</p>
  
  <pre><code>function countdown(counter) {
      x = counter;
      if (x &gt; 0) {
          x--;
          alert(x + "/5");
          if (x &gt; 0) {
              setTimeout(function () {
                  countdown(x);
              }, 500);
          }
      }
  };
  
  countdown(6);
  </code></pre>
  
  <p>But I'd like to be able to kill it, and start it again by pressing a button. I'd like to restart the loop, regardless of what number it's on when I press the button.</p>
  
  <p>I've got nowhere over the last few hours.</p>
  
  <p>Here's a jsfiddle: <a href="http://jsfiddle.net/4vtPH/4/" rel="noreferrer">http://jsfiddle.net/4vtPH/4/</a></p>