Operator Precedence
Operator precedence in JavaScript 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 JavaScript operators by priority from highest to lowest. Operators with the same precedence are evaluated in order from left to right.
Operator |
Describe |
. [] () |
field access, array subscripts, function calls, and expression groupings |
++ -- - ~ ! Delete new typeof void |
Unary operator, return data type, object creation, undefined value |
* / % |
Multiplication, division, modulo |
+ - + |
addition, subtraction, string concatenation |
<< >> >>> |
Shift |
< <= > >= instanceof |
Less than, less than or equal to, greater than, greater than or equal to, instanceof |
== != === !== |
Equal, not equal to, strictly equal, not strictly equal |
& |
Bitwise AND |
^ |
Per-bitwise XOR OR |
| |
by bit or |
&& |
Logic and |
|| |
Logical OR |
?: |
Conditions |
= op= |
Assignment, assignment of operations |
, |
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.
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.
A finally, the assignment operation. Assign 11232 to Z.
The above mentioned is the entire content of this article, I hope you can enjoy.