Scenario: Consider the following is the part of code from a node web app.
app.get('/users/:id?', function(req, res, next){
var id = req.params.id;
if (id) {
// do something
} else {
next(); //or return next();
}
});
Issue: I am checking which one to go with just next()
or return next()
. Above sample code works exactly the same for both & did not show any difference in execution.
Question: Can some one put light on this, when to use next()
and when to use return next()
and some important difference?