The grouping operator is a pair of parentheses placed around an expression or expressions to control the precedence of evaluation in expressions so that the sub-expressions are evaluated in the correct order. It is also used to enclose the arguments to a function or method.
Placing parentheses around expressions controls the order in which they are evaluated and can override the normal precedence that operators assume. This allows delete and typeof operations to be applied to expressions in parentheses for example.
Controlling the precedence of expressions allows operators with lower precedence to be evaluated ahead of the higher priority expression operators. For example:
A + B * C
by implication is executed like this:
A + (B * C)
A and B can be added before the multiplication like this:
(A + B) * C
This forces the addition to occur before the multiplication and is functionally equivalent to:
A*C + B*C
The associativity is left to right.
Refer to the operator precedence topic for details of execution order.
Prev | Home | Next |
Greater than or equal to (>=) | Up | H |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |