Design comparison
SolutionDesign
Solution retrospective
What are you most proud of, and what would you do differently next time?
loading icon
What specific areas of your project would you like help with?Js async
Community feedback
- @Alex-Archer-IPosted 4 months ago
Hi!
Basically the async-await pattern and fetch-than chain doing the same thing, it's just different syntax. At first you need to declare function with
async
keyword. Than you can useawait
in those parts of the function which must be executed with potential delay.// Here you declare that this is async function const fetchAdvice = async () => { // Than you use await keyword anytime you need to perform async code. // The function will not be executed further till it get the response. let response = await fetch('https://api.adviceslip.com/advice'); // You can perform some code here if need. // Here is an analog of this part - .then(response => response.json()) const advice = await responce.json(); // And work with advice content. };
Hope this helps. If you have any questions fell free to ask. Good luck =)
Marked as helpful1@Adrianocode19Posted 4 months ago@Alex-Archer-I Thank you very much for your help, I'm happy to analyze my code, I had studied asynchronous js but I forgot about await
1
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord