The operator priority in Javascript is a set of rules. This rule controls the order in which operators are executed when calculating expressions. Operators with higher priority are executed before operators with lower priority. For example, multiplication is performed before addition.
The following table lists JavaScript operators based on the highest to lowest priority. Operators with the same priority are evaluated from left to right.
| Operator |
Description |
| . [] () |
Field access, array subscript, function call, and expression grouping |
| ++ ---~ ! Delete new typeof void |
Unary operator, returned data type, object creation, undefined Value |
| */% |
Multiplication, division, modulo |
| +-+ |
Addition, subtraction, string connection |
| <>>>> |
Shift |
| <<=>> = Instanceof |
Less than, less than or equal to, greater than, greater than or equal to, instanceof |
| =! ===! = |
Equal to, not equal to, strictly equal, not strictly equal |
| & |
Bitwise AND |
| ^ |
Bitwise OR |
| | |
By bit or |
| && |
Logic and |
| | |
Logic or |
| ? : |
Condition |
| = Op = |
Assignment and operation assignment |
| , |
Multiple evaluate |
Parentheses can be used to change the order of evaluation determined by the operator priority. This means that the expressions in parentheses should be evaluated before they are used for the rest of the expressions.
CopyCode Code: z = 78*(96 + 3 + 45)
There are five operators in this expression: =, *, (), +, and another +. Based on the operator priority rules, they are evaluated in the following order: (), +, +, *, =.
Evaluate the expressions in parentheses. There are two addition operators in parentheses. Because the two addition operators have the same priority, they are evaluated from left to right. Add 96 and 3 first, and then add them to 45. The result is 144.
Then there is a multiplication operation. Multiply 78 by 144, and the result is 11232.
A is the value assignment operation. Grant the value 11232 to Z.
= Operator: If two values are of different types, false is returned. If both values are of the number type and the values are the same, true is returned. If both values are of the stirng type and the values have the same string content, returns true. If both values are true or false, returns true. If both values point to the same object, arraya, or function, returns true. If both values are null or undefined, returns the true = Operator. If the two values have the same type, the = comparison is performed, and the = comparison value is returned. If the two values do not have the same type, it is also possible to return true. If one value is null and the other value is undefined, true is returned. If one value is string and the other value is number, converts string to number and then compares. If a value is true, it is converted to 1 and then compared. False is converted to 0. If one value is an object and the other is a number or string, the object is converted to the original type by using valueof () or tostring () and then compared.
Detailed source reference: http://www.jb51.net/article/17542.htm