How to use the JavaScript keyword Async
This article mainly explains "how to use the JavaScript keyword Async". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use the JavaScript keyword Async.
JavaScript keyword Async syntax
The keyword async before the function returns promise:
Example
Async function myFunction () {
Return "Hello"
}
Equivalent to:
Async function myFunction () {
Return Promise.resolve ("Hello")
}
Here is how to use Promise:
MyFunction (). Then (
Function (value) {/ * Code for success * /}
Function (error) {/ * Code in case of error * /}
)
Example
Async function myFunction () {
Return "Hello"
}
MyFunction (). Then (
Function (value) {myDisplayer (value);}
Function (error) {myDisplayer (error);}
)
Or more simply, because you expect normal values (normal responses, not errors):
Example
Async function myFunction () {
Return "Hello"
}
MyFunction (). Then (
Function (value) {myDisplayer (value);}
)
At this point, I believe you have a deeper understanding of "how to use the JavaScript keyword Async". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!