But there are a lot of functionalities in our program which make our code Asynchronous and one of them is the Async/Await functionality. Async/Await is the extension of promises which we get as support in the language.
The following sections will describe more about async and await in detail along with some examples (individual as well as combined examples of async-await):
Await: Await function is used to wait for the promise. It could be used within the async block only. It makes the code wait until the promise returns a result. It only makes the async block wait.
1 2 Hello World
Notice that the console prints 2 before the “Hello World”. This is due to the usage of the await keyword.
Example 3: In this example, we will be implementing several promises in a method and then that method we will use for displaying our result.
[ 'Hello', ' GeeksforGeeks..' ]
Supported Browsers: The browsers supported by Async/Await Function are listed below:
- Google Chrome 55 and above
- Firefox 52 and above
- Apple Safari 10.1 and above
- Opera 42 and above
- Edge 14 and above