title: How does JS Promises work internally?
body: <p>I would like to know how js promises work internally.</p>
  
  <p>I've googled but I couldn't find the answer (or I didn't know how to google).</p>
  
  <p>I don't know how it gets back to you.</p>
  
  <p>Lets say I have this client code:</p>
  
  <pre><code>function whatever() {
      doSomethingLocally;
  
      callPromiseThatGoesAllOverTheWorldAndThenGetsBackToYou()
          .then(
              doSomethingLocallyAgain
          );
  
       doSomeOtherThingLocally;
  }
  </code></pre>
  
  <p>I would like to know how, when the promise is fulfilled, it gets back to the right point in code (that 'doSomethingLocallyAgain').</p>