I'm currently transitioning from promises to async await. And its been easier to reason about code. I just have a question on if using way to check for undefined is good. The code is being used in nodejs and checking against a database. The code goes something like this.
Edit: I am aware that I'm supposed to catch for errors. I just got lazy here.
// This is a hypothetical function
async function retrieveUser(userID){
let user = await databasefetchfuction(userID);
if(user) return user;
return;
}
controller.getUser = async function(req,res){
let user = await retrieveUser(req.params.userID);
if(!user){ // Is this ok?
return res.status(404).json();
}
return res.status(200).json({ user });
}
I was if doing this is fine or if I should explicitly check for undefined using user === undefined
?