function a() { return 1; } function b() { return(1); } I tested the above code in Chrome's console, and both returned 1.
function c() { return "1"; } function d() { return("1"); } I also tested the code above, and both of the functions returned "1".
So what is the difference between using return and return()?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With