silent_coder silent_coder - 2 months ago 13
Javascript Question

Why use parentheses when returning in Javascript

In the Restify framework code I found this function:

function queryParser(options) {


function parseQueryString(req, res, next) {
//some code goes there
return (next());
}

return (parseQueryString);

}


Why would the author write
return (next());
and
return (parseQueryString);
? Does it need parentheses there and if so, why?

Answer Source

It doesn't need to be that way but it's valid javascript. Actually it's quite uncommon to see such syntax. I guess it's a personal preference of the author.