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

438
Views
Can someone explain pls why the Promise returns pending in the first function, but resolved in the other two?

Can someone explain pls why the Promise returns pending in the first function, but resolved in the other two? When i read MDN it states that just using the word async wont make the code inside asynchronous (we need to use the word await as well). Also, I return the promise explicitly, since I use resolve() (which should return fulfilled promise as in two other functions, yet it returns Pending in the first function). I provided the code below.

const testFunc = async() => {
  return new Promise((resolve,reject)=> {
    resolve()
  })
}

const testFunc2 = () => {
  return new Promise((resolve,reject)=> {
    resolve()
  })
}

const testFunc3 = () => {
  return new Promise((resolve,reject)=> {
    resolve()
  })
}

testFunc().then(()=> console.log("Hello")).then(()=> console.log("there")).then(()=> console.log("Obi One"))

testFunc2().then(()=> console.log(1)).then(()=> console.log(2)).then(()=> console.log(3))

testFunc3().then(()=> console.log(4)).then(()=> console.log(5)).then(()=> console.log(6))

console.log(testFunc())
console.log(testFunc2())
console.log(testFunc3())

// Results in the console: 
// Promise {<pending>}
// Promise {<fulfilled>: undefined}
// Promise {<fulfilled>: undefined}
// 1
// 4
// 2
// 5
// Hello
// 3
// 6
// there

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

0

Thats because testFunc (the function with async keyword) is equalevent to this:

const testFunc = () => {
  return new Promise((resolve,reject)=> {
    resolve(new Promise((r) => {
      r()
    }))
  })
}

and not

const testFunc = () => {
  return new Promise((resolve,reject)=> {
    resolve()
  })
}
about 4 years ago · Juan Pablo Isaza Report

0

Using async queues the executer as a microtask.

Read about it here: https://whistlr.info/2021/async-and-tasks/

The key point:

When you write an asynchronous function, you force the caller to use a microtask to read its result. This is the case even if you don't await inside it—it will return a Promise regardless

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!