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.
Copy Code code as follows:
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.
= = Operator: If two value types are different, return FALSE if two values are of type number, and the values are the same, return true if two values are stirng and the string content of two values is the same, return true if two values are true or false , return True if all two values point to the same Object,arraya or function, return TRUE if two values are null or all undefined, return true = = Operator: If two values have the same type, a = = comparison is made, and the return = = = Comparison value If two values do not have the same type, it is possible to return true if one value is null and another value is undefined, returns true if one value is a string and the other is number, the string is converted to number and then compared If a value is true, it is converted to 1 and then compared, false to 0 if one value is object and the other is number or string, Object uses valueof () or ToString () to convert to the original type and then compare
Detailed Source reference: http://www.jb51.net/article/17542.htm