The question is about the grouping operator (), or precedence operator.
Preliminary note: parenthesis used in "function [name](){}" are part of the syntax of the function (idem for function invokation), not a grouping operator.
The grouping operator has the highest precedence over any other operator, precisely because its role is to alter the precedence of the expression contained in it (i.e. in parenthesis). This means that the expression within parenthesis is fully evaluated before its value is used in the remainder of the expression. Henceforth:
(1+2); // strictly equivalent to 1+2;
// because nothing more in the expression
or:
var x = ("3"==3)? "ok":"ko"; // grouping operator is useless as well
... but (as stated in Barmar'answer):
the syntax "function(){return 1;}", when put between (), is operated by the grouping operator, and is considered as an expression to be executed before being used in the full statement, and there are 2 consequences:
- an anonymous function is allowed, for we are in a function expression;
- to be executed, a function expression must have arguments provided to its parameters, and -if you are expecting the return value(note2)- a second pair of parenthesis is mandatory, to contain the arguments, or no argument.
(function(){return 1;}());
Note2: the original question was mentioning the example:
(function(){return 1} + "text"); //-> function(){return 1}text
as not returning a Syntax Error: it's correct, but it returns the code of the function as a string value, not the value 1, followed by the string 'text'. Why? because no parenthesis were provided for the execution. We should rather write:
(function(){return 1}()) + "text"; //-> 1text