The next a synchronous question in JavaScript will be, for sure, a sink of eight.
And here actually one must read the previous exercise like mapping users with two premises in async
await function.
As you can see here, we have our users user statuses and two functions get users and get user premises.
And actually, I commented out our previous code so we can copy parts of it.
And the first thing that we must do here is create additional function.
Why is that?
Because you are not allowed to write this in Kuwait directly in the root part of your JavaScript file.
This is why here, first of all, we must create something like get mapped users, maybe because we
want to make it in the synchronous function.
This is why here we're using our async keyword and here we are creating our function, and this assumed
keyword allows us to use a wait inside.
But we want to do number one to get our users and user statuses.
So here I can simplify it.
Users, don't forget this debate.
And here we just try and get users.
And if you forget here, wait, then here won't get our users, but you will get here a promise.
And this is not what we want.
We want to resolve our promise.
The next line here will be user statuses.
And here we want to get our get user statuses.
And obviously, as you can see, this code is much, much easier to read because we don't have any then
we don't have promised.
So it looks like it is simple asynchronous code because the lines are executed one by one.
And after this extra loop of want to copy paste our mapping and put it here because we won't change
it, and it doesn't make any sense to create additional function because inside this function, we have
just two lines.
This is why here we can write const mapped users.
And here were signed and users that map and will make in exactly the same stuff like we did in previous
video.
So after this headline, we already have our map data.
So here we can write console.log map to users.
And here we can check our mapped users.
We also must call somewhere our get mapped users function.
And if we don't need to write here, wait or something because we simply call in the synchronous function.
Now I will reload this page.
As you can see, we're getting mapped users.
And this is our response, which actually means this code is working correctly and this code is looking
super readable because we use here, as in Kuwait.
But this is not enough.
We always want to prep our write code.
We strike.
Why is that?
Because of here, we will get some error.
Then we will never see it.
We will have an error and code promised.
This is where here we want at the beginning to write try.
And here at the end, after our console.log, we want to close it.
And right here, OK?
And here we are getting our error and inside our case, we want to write something like console.log
Azure and here is Arrow that we can get.
In this case.
We're on the safe side and we know if some asynchronous code is not working here of getting some errors,
we will then throw an arrow here inside the cage.
Let's check this out.
Our code is still working and we successfully use this in Kuwait to write our promises with it.