title: What is the JavaScript version of sleep()?
body: <p>Is there a better way to engineer a <code>sleep</code> in JavaScript than the following <code>pausecomp</code> function (<a href="http://www.sean.co.uk/a/webdesign/javascriptdelay.shtm" rel="noreferrer">taken from here</a>)?</p>
  
  <pre><code>function pausecomp(millis)
  {
      var date = new Date();
      var curDate = null;
      do { curDate = new Date(); }
      while(curDate-date &lt; millis);
  }
  </code></pre>
  
  <p>This is not a duplicate of <a href="https://stackoverflow.com/questions/758688/sleep-in-javascript-delay-between-actions">Sleep in JavaScript - delay between actions</a>; I want a <em>real sleep</em> in the middle of a function, and not a delay before a piece of code executes.</p>