In my journey so far, I realized one of my favorite things javascript does is the async/await function. Learning how functions are called by order really helped solidify the concept for me.
But you may ask, what is the difference? When do I use a regular function and when do I use an async? - The answer lies in what you want to do and what you are working with.
In a synchronous function, javascript implements and reads your code in the order it is writte (that is why Scope is so important!) In async, this tells javascript, "hey do not run this yet, I need more data wait for data to come back to implement the rest."
This is very useful when calling APIs. When you are requesting data from an API, although it seems to come quickly, we do not really know when exactly the API's data will come to you since it is not a data set that you own.
In an async await, you tell the function to wait. In API use-case you tell it to wait until you receive a response and convert it to Json so it is usable.
Top comments (0)