A lot of people (myself included!) make the mistake of jumping right into frameworks/libraries/projects, without having a solid understanding of the language itself so that’s why I’m doing these blog posts !!
A lot of the material I’m using is from W3schools (shout out them!). See here for more info: https://www.w3schools.com/js/js_async.asp
Check out my affiliate links to get yourself a discount:
Discount CODE: ‘VNCS’
Diamond 3 Month Split: https://www.papareact.com/a/2147491767/fGcDDEcG
GitHub Repo: https://www.papareact.com/a/2147491768/fGcDDEcG
Platinum 3 Month Split: https://www.papareact.com/a/2147491769/fGcDDEcG
As always, before I get into the post; make sure to applaud and share, so this reaches more people!
The keyword ‘Async’ makes a function return a promise.
What is a Promise?
At this point, you might be thinking ‘What is a Promise?’.
Typically these are the return values:
Pending — Undefined.
Fulfilled — Result object.
Rejected — Error object.
More About Async:
See this example from W3Schools:
This keyword makes a function WAIT for a promise. Both ‘async’ and ‘await’ typically go hand in hand when creating functions!
Await must be used inside of a function that makes use of the ‘async’ keyword.
This example creates a promise (hence async), the function then waits for it and then if successful, returns ‘I love you !!’!
This example is similar but waits 3000 before returning the promise!
This example performs a GET request, waiting for it to be complete, before outputting the information about it!
As always, remember to applaud and share this post, helping it reach more people!!!
Follow Vikram Nayyar CS on all platforms!!!