Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javascript Async & Await #39

Open
sophryu99 opened this issue Mar 2, 2022 · 0 comments
Open

Javascript Async & Await #39

sophryu99 opened this issue Mar 2, 2022 · 0 comments

Comments

@sophryu99
Copy link
Owner

Async keyword

The word “async” before a function means one simple thing: a function always returns a promise. Other values are wrapped in a resolved promise automatically.

async function f() {
    return 1
}

f().then(result => console.log(result));

Await keyword

However, this way of processing asynchronous functions can be unintuitive.
The “await” keyword provides a much clearer way to process asynchronous function. With “await”, you can process async functions just like synchronous ones.

async function f() {
    return 1
}

let result = await f();
console.log(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant