Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

309
Views
Binding multiple callbacks for promises returns resolve value of first promise, not second

I have the following code as part of some coding practice I am doing:

var promise = new Promise(function(resolve, reject) {
    setTimeout(function() {
        resolve('hello world');
    }, 2000);
});

var promiseTwo = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve('hello again!');
    }, 2000);
});

promise.then(promiseTwo).then((data) => {
    console.log(data)
})

When the data is logged, it reads hello world and not hello again!. Why is that? My thinking was that the line promise.then(promiseTwo).then((data) => { console.log(data) }) would resolve the first promise, then pass the second promise in as a callback which would resolve to hello again!. Why does the resolve in promiseTwo never get return from the .then method?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Because you're not returning promiseTwo in then, you're simply calling it, try:

var promise = new Promise(function(resolve, reject) {
    setTimeout(function() {
        resolve('hello world');
    }, 2000);
});

var promiseTwo = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve('hello again!');
    }, 2000);
});

promise.then(() => promiseTwo).then((data) => {
    console.log(data)
})

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!