FAQ: Async Await - Writing async Functions

This community-built FAQ covers the “Writing async Functions” exercise from the lesson “Async Await”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Asynchronous JavaScript

FAQs on the exercise Writing async Functions

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Hello, for the last step, at first i typed node app.js and it returned the right result. but then i saw the hint to suggest typing node someFileName.js, i tried and it returned an error like can’t find module someFileName(which i didn’t see either), why not use note app.js?

1 Like

how did you solve it

hello! Didnt understand entirely how the second point logs out ( 2. I bought ${beanType} beans because they were on sale ).

Is this because we invoke shopForBeans function when it is assigned to value variable?

1 Like

I tried to use the setTimeout function inside the async await function from the 4th unit of asynchronous functions but it resulted in an error. Is it because it can only be used on newly written promises? If so, how could I set a timeout outside a promise?

This would be the code:

async function getBeans() { setTimeout(() => {console.log(1. Heading to the store to buy beans…); let value = await shopForBeans(); console.log(3. Great! I’m making ${value} beans for dinner tonight!);}, 2000) }

Thanks!

1 Like

My understanding of asynchronous code is that it allows Javascript code to continue while waiting for something to resolve.

But then in the async/await section there is a statement that the await keyword halts the execution of an async function until a promise is no longer pending? Is this saying that just the function halts but then there is other code going on after that?

I’m also not very clear on when the setTimeout() is used? I understand that it delays something a certain amount of seconds, but not when you should use it. In the examples it is sometimes used, sometimes not and I don’t know why.