Currently this is my Code:
async function getUser(ID){
//Code for Building SQL query
return await getUserFromDb(query);
}
I just installed eslint and I read that it is useless to write "await" in a return Statement and that only slows down the function.
After removing the await from the return row it says now that I dont have any await in my async function.
Do I still Need to make the function async? In my main function I call user = await getUser();. Do it be rigth to remove the await here and from the function? will it stil be ansyc?
So is this:
async function getUser(ID){
//Code for Building SQL query
return await getUserFromDb(query);
}
async function main(){
console.log("User 1: test");
console.log("User 2: " + await getUser(424).Name);
console.log("User 3: test");
}
the same as this?:
function getUser(ID){
//Code for Building SQL query
return getUserFromDb(query);
}
async function main(){
console.log("User 1: test");
console.log("User 2: " + getUser(424).Name);
console.log("User 3: test");
}
getUserFromDbis asynchronous, then the two are not equivalent - async functions always return a promise, so in the last code, you are returning the promise and trying to get.Namefrom it, which doesn't exist on a promise.