title: Javascript promise "then" always runs even though the promise failed to execute
body: <p>I want the third "then" to not be executed when the second "then" is called. However, it still calls the third "then" even though the promise is rejected (the second "then" is called) and the code returns "rejected" and then "undefined". How to not run the third "then" so the "undefined" won't show up?</p>
  
  
  
  <pre><code>var FirstPromise = function() {
  
    let promiseme = new Promise(function(res, rej) {
  
      if ('a' == 'b') {
        res(1);
      } else {
        rej('rejected');
      }
    })
  
    return promiseme;
  };
  
  function succeddcallback(msg) {
    return msg * 2;
  }
  
  function errorcallback(msg) {
    console.log(msg);
  }
  
  FirstPromise()
    .then(succeddcallback, null)
    .then(null, errorcallback)
    .then(function(succedded) {
      console.log(succedded);
    }, function(failed) {
      console.log(failed);
    })
  </code></pre>