Skip to content

Javascript Async & Await #39

@sophryu99

Description

@sophryu99

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)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions