title: difference between resolve and onFulfilled
body: <p>What is the difference between </p>
  
  <p><code>resolve</code> and <code>onFulfilled</code> in javascript promises ?</p>
  
  <p>Similarly,  what is the difference between </p>
  
  <p><code>reject</code> and <code>onRejected</code> ?
  In simple words, I would just ask how does onsuccess callback of Promise.then(onsuccess, onreject) differs from Promise.resolve ()?</p>
  
  <p>I am reading Javascript with Promises by Daniel Parker.
  The book has mentioned both of them but I have not realized the difference between two yet.</p>
  
  <p>While describing then in promises:</p>
  
  <blockquote>
    <p>promise.then</p>
    
    <p>promise.then([onFulfilled], [onRejected]) returns promise</p>
    
    <p>The promise.then() method accepts an onFulfilled callback and an
    onRejected
        callback. People generally register onRejected callbacks using promise.catch()
        instead of passing a second argument to then . The function then returns a promise that is resolved by the return value of the
        onFulfilled or onRejected callback. Any error thrown inside the callback rejects the new promise with that error.</p>
  </blockquote>
  
  <p>Also,</p>
  
  <p><strong>Promise.resolve</strong></p>
  
  <blockquote>
    <p>Promise.resolve([value|promise]) returns promise The Promise.resolve()
    function is a convenience function for creating a promise that is
    already resolved with a given value. If you pass a promise as the
    argument to Promise.resolve(), the new promise is bound to the promise
    you provided and it will be fulfilled or rejected accordingly.</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code>function settled(promises) {
   var alwaysFulfilled = promises.map(function (p) {
   return p.then(
   function onFulfilled(value) {
   return { state: 'fulfilled', value: value };
   },
   function onRejected(reason) {
  
   return { state: 'rejected', reason: reason };
   }
   );
   });
   return Promise.all(alwaysFulfilled);
  }
  };
  </code></pre>