Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the JavaScript keyword Async

Shulou Source: shulou.com Published: 2022-06-01 04:23:05 09月22日 Update

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!

Tags: Keywords keywords examples code content functions methods learning practicality depth success interest practicality practicality simplicity of operation more friends normal values websites grammar Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MySQL NVidia macOS OPPO Reno