Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript REST APIs with Express Managing Data and Asynchronous Code Managing Data and Async Code Quiz

Fill in the blank to use async/await syntax

Idk what to fill in the blanks

1 Answer

Dane Parchment
MOD
Dane Parchment
Treehouse Moderator 11,077 Points

It's asking you to use the async and await syntax that you learned. I won't give the specific answer to this quiz since that's for you to figure out.

But here's how the syntax works.

Async: Marks the function as an asynchronous function that will return a promise, as such it should be used as a tag for a function. Like so:

// Using normal function syntax
async function myFunc() {}

// Using arrow syntax (we don't use the function identifier so we just add the async tag to the function definition)
const myFunc = async () => {}

Await: Can only be used in an asynchronous function and marks the value as a resolved promise value. Basically, when the code comes across the await tag, it will pause the code and wait until that line of code runs and then return the resulting value.

Use it like so:

// Using normal function syntax
async function myFunc() {
   let val = await promise.resolve(10);
}

// Using arrow syntax (we don't use the function identifier so we just add the async tag to the function definition)
const myFunc = async () => {
  let val = await promise.resolve(10)
}

note that the await doesn't have to precede specifically promise.resolve. It can precede any value or function call

Hope that helps, if you are still confused I recommend going back and rewatching the sections related to Async/Await, to better understand the syntax.