Part 3: I Asked 25 Developers This Async JavaScript Question — Only 3 Got It Right

“It worked on my local” isn’t an async strategy. It’s a bug in disguise.

Async JavaScript Question

Let’s do a Role Play😄

You’re in a frontend interview.

The interviewer shares this code snippet in chat:

async function fetchData() {
return await Promise.resolve('Data loaded');
}
function getData() {
const data = fetchData();
console.log(data);
}
getData();

Quick Question — what will it log?

No debugger. No search. Just your brain.

Use your brain -GIF

What Most People Say

“It should log 'Data loaded' right?” I know you’re guessing it must not be ‘Data loaded’ otherwise why this blog?

and You’re right. ‘Data Loaded’ is not the answer here.

And that’s the problem with how most devs “learn” async/await.

They understand the syntax, not the behavior. I was one of them at some point of time.

The Actual Output

Promise { <fulfilled>: 'Data loaded' }

Why?

Because fetchData() is async. That means it always returns a promise, even if the value is already resolved.

So when you call console.log(data), you're logging a promise, not the value it resolves to.

Fix It

To actually see 'Data loaded' in the console:

async function getData() {
const data = await fetchData();
console.log(data);
}

Or, if you’re outside an async function:

fetchData().then(console.log);

Real-Life Pain Point

This is why APIs in production sometimes “randomly fail.”

Someone wrote:

const result = getAPIData();
if (result.success) {
// do something
}

But getAPIData was async—and the check ran on a pending promise.

Your app? 🧨 Broken in silence. Your Production crashed loudly 💥

You made your point -GIF

Want Another Round? Try This

What does this log?

console.log('Start');
setTimeout(() => {
console.log('Timeout');
}, 0);
Promise.resolve().then(() => {
console.log('Promise');
});
console.log('End');

Think of it, I know you can.

Let’s test your expertise. Answer this in the comments and let’s see who gets it right ?— without running it(No cheating😂).

Quick Takeaways

  • async always returns a promise.
  • await works only inside an async function.
  • setTimeout delays go in the task queue.
  • Promises use the microtask queue and are prioritised.

Your Turn

What async JS trick confused you the most?

Drop it in the comments, and I might include it in Part 4.

At Dev Simplified, We Value Your Feedback 📊

👉 Follow us to not miss any updates.

👉 Have any suggestions? Let us know in the comments!

👉 Subscribe for free and join our growing community!