What is the difference between return and return()?
Solution 1:
The same as between
var i = 1 + 1;
and
var i = (1 + 1);
That is, nothing. The parentheses are allowed because they are allowed in any expression to influence evaluation order, but in your examples they're just superfluous.
return
is not a function, but a statement. It is syntactically similar to other simple control flow statements like break
and continue
that don't use parentheses either.
Solution 2:
There is no difference.
return
is not a function call, but is a language statement. All you're doing with the parentheses is simply grouping your return value so it can be evaluated. For instance, you could write:
return (x == 0);
In this case, you return the value of the statement x == 0
, which will return a boolean true
or false
depending on the value of x
.