DEV Community

Discussion on: Basics of Async and Await

Collapse
 
aminnairi profile image
Amin • Edited

Hi there, great set of notes on the subject!

I would add to your notes that returning any value from any async function makes it a promise as well. So returning a number will make it a Promise<number> in the end. Which can simplify asynchronous function definitions from this

function promiseNumber() {
    return Promise.resolve(123);
}

to this

async function promiseNumber() {
    return 123;
}

Of course, this will work with anything.

Collapse
 
pachicodes profile image
Pachi 🥑

Thank you Amin!

Collapse
 
mateiadrielrafael profile image
Matei Adriel

Async is supposed to come before the function keyword

Collapse
 
aminnairi profile image
Amin

Yes you are right, gonna correct my mistake right away. Thank you.

Collapse
 
davjvo profile image
Davmi Jose Valdez Ogando

Really good note didn't know this