Q:

The significance of "return" in this Javascript code

I am new to Javascript and following this tutorial: http://mcavage.me/node-restify/#Error-handling
 server.get('/hello/:name', function(req, res, next) {
  return database.get(req.params.name, function(err, user) { // Why call "return" here?
    if (err)
      return next(err);

    res.send(user);
    return next();
  });
});

The 2nd line calls return although I tried without return, it also worked. Could someone shed a light here the significance of calling "return" here? Thanks.
Based on @Pointy's answer, I just would like to add that the question presumes "next()" function doesn't return any value.

A:

The return statement causes a function call to exit at that point. If the statement includes an expression, then the function returns the value of the expression back to the calling environment.
In this case, the function in the first line (the if statement) detects an error, and so it passes that error along to its own callback (the function referred to by the "next" parameter). It then returns whatever that function returns.
Without the return statement on that line, the behavior of the function would be significantly different, so it doesn't actually "work" without it. It might work sometimes, but as that statement is involved in error handling you won't see the bug unless there's an error.

