JavaScript operator precedence
JavaScript operator precedence describes the order in which operations are performed when a computer evaluates an expression. Operations with higher priority are performed first, and then operations with lower priority are performed. For example, we often say that multiplication and division are performed first, and then addition and subtraction operations are performed.
Precedence | Operator | Description | Associativity |
---|---|---|---|
1 | [] 、. 、() | Field access, array indexing, function calls, and expression grouping | From left to right |
2 | ++ -- -~!delete new typeof void | Unary operator, return data type, object creation, undefined value | From right to left |
3 | *、/、% | Multiplication, division, remainder | From left to right |
4 | +、- | Addition, subtraction, string concatenation | From left to right |
5 | <<、>>、>>> | Left shift, right shift, unsigned right shift | From left to right |
6 | <, <=, >, >=, instanceof | less than, less than or equal to, greater than, greater than or equal to, whether an instance of a specific class | from left to right |
7 | ==, !=, ===, !== | equal, not equal, all equal, not all equal | from left to right |
8 | & | bitwise AND | from left to right |
9 | ^ | Bitwise XOR | From left to right |
10 | | | Bitwise OR | From left to right |
11 | && | Short-circuit AND (logical AND) | From left to right |
12 | || | Short-circuit OR (logical OR) | From left to right |
13 | ?: | Conditional operator | From right to left |
14 | =、+=、-=、*=、/=、%=、&=、|=、^=、<、<=、>、>=、>>= | Mixed assignment operators | From right to left |
15 | , | Multiple calculations | Calculate by priority, then from right to left |