title: Javascript promises setTimeout execution
body: <p>I have been playing with Promises, but I am having trouble understanding what is happening with the following code:</p>
  
  <pre><code>const promise = new Promise((resolve, reject) =&gt; {
    console.log('Promise started')
    resolve('Success')
  })
  
  setTimeout(() =&gt; {
    console.log('Log inside first setTimeout')
  }, 0)
  
  promise.then(res =&gt; {
    console.log('Promise log after fulfilled ❌')
  })
  
  setTimeout(() =&gt; {
    console.log('Log inside second setTimeout')
  }, 0)
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>Promise started 
  Promise log after fulfilled ❌ 
  Log inside first setTimeout 
  Log inside second setTimeout 
  </code></pre>
  
  <p>Why not the below output?</p>
  
  <pre><code>Promise started 
  Log inside first setTimeout 
  Log inside second setTimeout 
  Promise log after fulfilled ❌ 
  </code></pre>
  
  <p><strong><em>Between <code>setTimeout(fn, 0)</code>fn call and <code>resolve()</code>fn call which will be given priority?</em></strong></p>
  
  <p><strong><em>Is it dependent on browser implementation details?</em></strong></p>