Home >Web Front-end >JS Tutorial >A brief discussion on the priority of operators in JavaScript_javascript skills
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. Operators with higher precedence are executed before operators with lower precedence. For example, multiplication is performed before addition.
The following table lists JavaScript operators from highest to lowest precedence. Operators with the same precedence are evaluated from left to right.
Operator | Description |
. [] () | Field access, array subscripting, function calls, and expression grouping |
-- - ~ ! delete new typeof void | Unary operators, return data types, object creation, undefined values |
* / % | Multiplication, division, modulo |
- | Addition, subtraction, string concatenation |
10e3fdaca48eb0367c6d60dbc98f885d> >>> | Shift |
7cb9091baf3e2c81106f6565e75575c8 >= instanceof | Less than, less than or equal to, greater than, greater than or equal to, instanceof |
== != === !== | Equal, not equal, strictly equal, not strictly equal |
& | Bitwise AND |
^ | Bitwise XOR |
| | Bitwise OR |
&& | Logical AND |
|| | Logical OR |
?: | Conditions |
= oP= | Assignment, operation assignment |
, | Multiple evaluation |
Parentheses can be used to change the order of evaluation determined by operator precedence. This means that the expression enclosed in parentheses should all be evaluated before it is used in the rest of the expression.
z = 78 * (96 + 3 + 45)
There are five operators in this expression: =, *, (), , and another . According to the rules of operator precedence, they will be evaluated in the following order: (), , , *, =.
The expression inside the parentheses is evaluated first. There are two addition operators in parentheses. Because both addition operators have the same precedence, they are evaluated from left to right. First add 96 and 3, then add that sum to 45, and you get 144.
Then comes the multiplication operation. 78 times 144 gives us 11232.
A is the assignment operation at the end. Assign 11232 to z.
The above is the entire content of this article, I hope you all like it.