The Grouping Operator

Aside from being used in function calls, parentheses ( ) can also be used to group a phrase of code to override the precedence of various operators. Parentheses are also required in some statements, most notably if statements. Parentheses take the general form:

(expression)

The expression within the parentheses is evaluated and returned. Here are some examples:

if (x == y) {                 // Syntactically required for if statement
  trace("x and y are equal"); // Required for the function call
}
(5 + 6) * 7                   // Force a nonstandard order of operation
(x >= 100) || (y <= 50)       // Parentheses not required but added for legibility
x >= 100 || y <= 50           // No parentheses...a little harder to read

Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.