BeginnerCoder

Lesson 14 — async functions

Async functions return Promises

Whatever an async function returns is automatically wrapped in a Promise. If you call it without await you get the Promise itself (shown as Promise { <pending> }), not the value. To get the value, await the call inside another async function — or use .then.

async function getName() { return "Sam"; }
console.log(getName());        // Promise { 'Sam' }
getName().then((n) => console.log(n)); // Sam

Why it matters: "I got [object Promise] instead of my data" is one of the most common beginner bugs with APIs.

Want it another way?
Task

Make main print the score 42 instead of Promise { <pending> }.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.