function a() { return 1; }
function b() { return(1); }
I tested the above code in Chrome\'s console, and both returned 1
.
by adding parenthesis, we have made sure that javascript doesn't insert a semicolon before multiple statements written after return, for reference:- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Automatic_semicolon_insertion
example:
return
a + b;
is transformed to
return;
a + b;
by ASI.
The console will warn "unreachable code after return statement". To avoid this problem (to prevent ASI), you could use parentheses:
return (
a + b
);
code copied from:- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return