title: why does the setTimeout not get called when invoked from inside an infinite while loop
body: <p>I bumped into a funny problem, I was trying to invoke a function (which has a setTimeout in its body) from an infite loop, and it was never getting called, but when the loop is changed into not infite the call was happening!!</p>
  
  <p>this works :-</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var bar = function() {
      setTimeout(function() {
          console.log("1");
      }, 0);
  };
  
  var count = 4;
  while(count &gt; 0){
    bar();
    count --;
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>this never works . : -</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var bar = function() {
    setTimeout(function() {
      console.log("1");
    }, 1000);
  };
  
  while (true) {
    bar();
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>can anybody explain whats going on in here!
  how to call a function with a setTimeout in its body from an infinite loop?</p>