Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use return keyword when rendering a view?

I'm not sure if that's so important but I like clean code so here's my question :

I use node.js with express. I have declared routes that render views :

app.get("/", function(req, res){
    return res.render("index.jade");
});

Can I remove the "return" keyword like this :

app.get("/", function(req, res){
   res.render("index.jade");
});

I've found lots of examples with both syntax. Don't know which one to use.

Thanks.

like image 325
Benjamin Simon Avatar asked Jun 27 '13 12:06

Benjamin Simon


1 Answers

In your case it doesn't matter at all. However using return is a common method when using conditionals. For example:

app.get("/", function(req, res){
  if(req.whatever) {
    // Using return here will cause any code after to not be run
    return res.render("index.jade");
  }

  // Default action
  res.render("default.jade");
});
like image 189
Andreas Hultgren Avatar answered Sep 21 '22 14:09

Andreas Hultgren