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

166
Views
Promise not resolving even with status of fulfilled and target data on PromiseResult

I need help on this issue I'm experiencing (I have already searched Stack overflow extensively but could not solve it on my own).

I have the following "dummy" logic to test async/await behaviour:

const data = [1, 2, 3]

async function newData() {
  return data
}

async function getData() {
  const fetchedData = await newData();
  return fetchedData
}

console.log(
  (async () => await getData())()
)

Even though I have awaited for all Promise fulfillings, the following data is returned from the console log:

Console.log return

What am I doing wrong? Why doesn't the Promise return the value but remains pending even though it is 'fulfilled'?

Thanks in advance.

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

0

All async functions return a promise. That's why newData(), getData() and your async IIFE you have buried in a console.log() ALL return a promise. When you return a value from an async function, that returned value just becomes the resolved value of the promise that the async function returns. An async function NEVER returns the value directly.

So, even this:

(async () => await getData())()

is an async function that returns a promise.

To get the resolved value from an async function, you MUST use .then() or await:

// this must be inside an async function or
// in an environment where top level await is allowed
console.log(await getData());

or:

getData().then(result => {
    console.log(result);
});
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!