js|jscript| operations
Operator Precedence in JScript is a set of rules. This rule controls the order in which operators are executed when evaluating an expression. Operations with higher precedence are performed Fuxian to lower-priority operators. For example, multiplication is performed prior to addition.
The following table lists the JScript operators by priority from highest to lowest. Operators with the same precedence are evaluated in order from left to right.
Operator description
. [] () field access, array subscript, function call, and expression grouping
++--~! Delete new typeof void Unary operator, return data type, object creation, undefined value
*/% multiplication, division, modulo
+-+ addition, subtraction, string concatenation
<< >> >>> Shift
< <= > >= instanceof is less than, less than, greater than, greater than or equal to, instanceof
= =!= = =!== equals, does not equal, strictly equal, not strictly equal
& Bitwise AND
^ per-bitwise XOR OR
| by bit or
&& Logic and
|| Logical OR
?: Conditions
= op= Assignment, Operation assignment
, multiple evaluation
Parentheses can be used to change the order of evaluation that is determined by operator precedence. This means that the expression in parentheses should be evaluated before it is used for the remainder of the expression.
For example:
z = 78 * (96 + 3 + 45)
There are five operators in the expression: =, *, (), +, and another +. According to the rules of operator precedence, they will be evaluated in the following order: (), +, +, *, =.
First evaluate the expression inside the parentheses. There are two addition operators in parentheses. Because the two addition operators have the same precedence, they are evaluated from left to right. Add 96 and 3 first, then add them together with 45, and the result is 144.
Then there is the multiplication operation. 78 times 144, and the result is 11232.
Finally, the assignment operation. Assign 11232 to Z.