Operator precedence is a set of rules in JScript. It controls the order in which operations are performed when an expression is evaluated. Operations with a higher precedence are performed before those with a lower one. For example, multiplication is performed before addition.
The following table lists the JScript operators, ordered from highest to lowest precedence. Operators with the same precedence are evaluated left to right.
Operator | Description |
---|---|
. [] () | Field access, array indexing, function calls, and expression grouping |
++ - ~ ! delete new typeof void | Unary operators, return data type, object creation, undefined values |
* / % | Multiplication, division, modulo division |
+ - + | Addition, subtraction, string concatenation |
<< >> >>> | Bit shifting |
< <= > >= instanceof | Less than, less than or equal, greater than, greater than or equal, instanceof |
== != === !== | Equality, inequality, strict equality, and strict inequality |
& | Bitwise AND |
^ | Bitwise XOR |
| | Bitwise OR |
&& | Logical AND |
|| | Logical OR |
?: | Conditional |
= OP= | Assignment, assignment with operation |
, | Multiple evaluation |
Parentheses are used to alter the order of evaluation determined by operator precedence. This means an expression within parentheses is fully evaluated before its value is used in the remainder of the expression.
For example:
z = 78 * (96 + 3 + 45)
There are five operators in this expression: =, *, (), +, and another +. According to the rules of operator precedence, they are evaluated in the following order: (), +, +, *, =.