JavaScript Promise.settle and promise fulfillment vs rejection

Consider the following code that contains a simplified implementation of Bluebird's Promise.settle:

var a = Promise.reject('a');
var b = Promise.resolve('b');
var c = Promise.resolve('c');

var promises = [a,b,c];

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);
}

//Update status message once all requests finish
settled(promises).then(function (outcomes) {
  var count = 0;
  outcomes.forEach(function (outcome) {
    if (outcome.state == 'fulfilled') count++;
  });

  console.log(count + ' out of ' + outcomes.length + ' balances were updated');
});

This will log "2 out of 3 balances were updated". Why does this work differently than a plain Promise.all? Shouldn't alwaysFulfilled still contain a rejected promise as its first element?

The answer seems to lie in my confusion over how promises work. If I create a rejected promise in the console and .then it like so:

var a = Promise.reject('a');
var b = a.then(function() {}, undefined);
var c = a.then(undefined, function() {});

a
Promise {[[PromiseStatus]]: "rejected", [[PromiseValue]]: "a"}
b
Promise {[[PromiseStatus]]: "rejected", [[PromiseValue]]: "a"}
c
Promise {[[PromiseStatus]]: "resolved", [[PromiseValue]]: undefined}

Why is c "resolved"?

Answer:1

Is it possible to use CSS to highlight the section that has been linked to? If not can I get the #link in JavaScript some how? IE var section = $(window).link(); Thanks for your time

Is it possible to use CSS to highlight the section that has been linked to? If not can I get the #link in JavaScript some how? IE var section = $(window).link(); Thanks for your time

I am currently switching the menu of my site from pure JavaScript to jQuery. My menu has a rollout / rollin effect. The menu has an outer wrapper which has an onmouseout event set. If this fires, the ...

I am currently switching the menu of my site from pure JavaScript to jQuery. My menu has a rollout / rollin effect. The menu has an outer wrapper which has an onmouseout event set. If this fires, the ...

I need to call a js function everytime a key is pressed in a textbox: <html> <script> function checkValidity() { alert("Checking..."); } </script>...

I need to call a js function everytime a key is pressed in a textbox: <html> <script> function checkValidity() { alert("Checking..."); } </script>...

How to display the JSON response in jsp page through ajax... function doAjaxPost() { var name = $('#name').val(); var password = $('#password').val(); var gender = $('#gender')....

How to display the JSON response in jsp page through ajax... function doAjaxPost() { var name = $('#name').val(); var password = $('#password').val(); var gender = $('#gender')....

  1. display json response in html
  2. display json response in html table
  3. display json response in angular
  4. display json response in angular 6
  5. display json response in chrome
  6. display json response in browser
  7. display json response in angularjs
  8. display json response in ajax
  9. display json response javascript
  10. display json response in php
  11. display json response in jsp
  12. display json response in datatable
  13. display json response in angular 2
  14. display json response in jquery
  15. display json response in div
  16. display json response in html angular
  17. display ajax json response in html
  18. laravel display json response
  19. curl display json response
  20. react display json response