You could use all of them as all three are valid. But given your examples, only the first makes sense.
Each of your examples returns a Promise. You can either use a().then(/*...*/)
or await a()
(only within an async
function) to get their response when they resolve. Read more about Promise
or async
/await
in general.
function a() {
return Promise.resolve();
}
This is how you should write a function that returns a Promise.
async function a() {
return Promise.resolve();
}
This works as well, but only functions that actually use the await
keyword need to be annotated with async
. Functions that just return a Promise without using await
in their body do not need to be async
.
Async A(){
Return await promise //this seems very wrong but still...
}
This is just an unncessary step. Read more here and here.