Suppose consider the following example:
1st:
projectController.getProjectById = function(req,res){
return (res.status(200).send("Hey"));
}
2nd:
projectController.getProjectById = function(req,res){
res.status(200).send("Hey");
}
Look closely in both of my snippet, in 1st snippet I have written return (res.status(200).send("Hey")); and in 2nd snippet I have written res.status(200).send("Hey");.
My question is that if we don't write the return(...) in res.send() then also it will send the data to client side . Then what is meaning of wrapping res.send() inside return(...) .
I have searched in internet but remains unsatisfied with answer, can anyone provide the explanation of my question.
returnstatement allows for that instance of what thesendmethod returns (In this case, theResponseobject) to be passed to the caller of the function such that it can be reused again later on. You don't have to return it if you're not using the return value.sendmethod is that it's a method that does something and returns the same instance: expressjs.com/en/api.html#res)