title: Why code in Promise executes synchronously?
body: <p>In my project I have a very long running operation, so I decided to put it in a <code>Promise</code> because I thought that in this way I could continue to execute the other operations while the code inside the <code>Promise</code> was running.</p>
  
  <p>While debugging, I find out that the code outside the <code>Promise</code> executed only when the code inside the <code>Promise</code> finished executing.</p>
  
  <p>Here is an example of what I'm doing in my project (it simulates a long operation, so it takes a while):</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>new Promise(function(resolve, reject) {
    var i = 0;
    while (i &lt; 1000000000) {
      i++
    }
    console.log("Executing inside Promise");
  });
  
  console.log("Executing outside Promise");</code></pre>
  </div>
  </div>
  </p>
  
  <p>I am not really sure why this is happening and that's why I asked it. But I think that it is somehow related to the fact that the code inside the <code>Promise</code> is synchronous.
  Indeed when it is async (i.e. the <code>setTimeout()</code> method) it runs after the outside code finishes executing.</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>new Promise(function(resolve, reject) {
    setTimeout(function() {
      var i = 0;
      while (i &lt; 1000000000) {
        i++
      }
      console.log("Executing inside Promise");
    }, 3000)
  });
  
  console.log("Executing outside Promise");</code></pre>
  </div>
  </div>
  </p>
  
  <p>But I still can't figure out why the code inside the <code>Promise</code> is executing synchronously?
  Shouldn't it execute asynchronously?</p>