Hello friends!
Nice to see you back.
In this tutorial we are going to learn two new features of JavaScript async and await.
Let's try to explore what is async function as we make normal functions.
In our case test.
If I type async keyword before the function keyword, then it will become a async function.
But the question is what is the difference between a normal function and a async function?
Async function always return a promise, and we learn about promise in our previous videos.
And we know promise.
Return two type of function resolve and reject.
Based on this we do our further work.
If it resolve, then we call then function, and if our promise is rejected, then automatically call
catch function.
So our async function work like promise.
It may be resolve or reject.
Similarly, we can call then function for resolve and we can call catch function for reject.
Now the question is why we use the async function since we already have the promise method.
If you remember, there is a little complication in our promise method.
Every time we need to declare, resolve, or reject function in promise.
To resolve this kind of complication, JavaScript introduce async function.
It is very easy to operate just.
You need to type async keyword before the function keyword, and you don't need to change in your function.
And I want to tell one thing our promise function introduced in JavaScript, ES6 version and async function
introduce in JavaScript is 2017 version.
From here you can understand why JavaScript introduced async function.
The answer is simple to resolve, promise, complication.
All the things that we could do inside the promise method we can do in async function.
So without wasting your time, let's back to the Visual Studio Code Editor.