Get to know MDN better
此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。
運算子優先序(Operator precedence)決定了運算子彼此之間被語法解析的方式,優先序較高的運算子會成為優先序較低運算子的運算元(operands)。
當優先序相同時,使用相依性決定運算方向。範例如下:
a OP b OP c左相依性 (Left-associativity) ,表示處理順序為從左至右 (a OP b) OP c,反之,右相依性(right-associativity) 表示處理順序為從右至左 a OP (b OP c)。賦值運算符 (Assignment operators) 為右相依性,範例如下:
a 和 b 的預期結果為 5,因為賦值運算符 (Assignment operator) 為右相依性,因此從右至左返回值。一開始 b 被設定為 5,接著 a 也被設定為 5。
下方表格列出運算子的相依性,從高 (19) 到低 (1)。
| 19 | Grouping | 無 | ( … ) |
| 18 | Member Access | 從左至右 | … . … |
| Computed Member Access | 從左至右 | … [ … ] | |
| new (with argument list) | 無 | new … ( … ) | |
| 呼叫函式 | 從左至右 | … ( … ) | |
| 可選串連(Optional chaining) | 從左至右 | ?. | |
| 17 | new (without argument list) | 從右至左 | new … |
| 16 | 字尾遞增 | 無 | … ++ |
| 字尾遞減 | … -- | ||
| 15 | Logical NOT | 從右至左 | ! … |
| Bitwise NOT | ~ … | ||
| Unary Plus | + … | ||
| Unary Negation | - … | ||
| 字首遞增 | ++ … | ||
| 字首遞減 | -- … | ||
| typeof | typeof … | ||
| void | void … | ||
| delete | delete … | ||
| await | await … | ||
| 14 | Exponentiation | 從右至左 | … ** … |
| 13 | Multiplication | 從左至右 | … * … |
| Division | … / … | ||
| Remainder | … % … | ||
| 12 | Addition | 從左至右 | … + … |
| Subtraction | … - … | ||
| 11 | Bitwise Left Shift | 從左至右 | … << … |
| Bitwise Right Shift | … >> … | ||
| Bitwise Unsigned Right Shift | … >>> … | ||
| 10 | Less Than | 從左至右 | … < … |
| Less Than Or Equal | … <= … | ||
| Greater Than | … > … | ||
| Greater Than Or Equal | … >= … | ||
| in | … in … | ||
| instanceof | … instanceof … | ||
| 9 | Equality | 從左至右 | … == … |
| Inequality | … != … | ||
| Strict Equality | … === … | ||
| Strict Inequality | … !== … | ||
| 8 | Bitwise AND | 從左至右 | … & … |
| 7 | Bitwise XOR | 從左至右 | … ^ … |
| 6 | Bitwise OR | 從左至右 | … | … |
| 5 | Logical AND | 從左至右 | … && … |
| 4 | Logical OR | 從左至右 | … || … |
| Nullish Coalescing | 從左至右 | … ?? … | |
| 3 | 條件運算 | 從右至左 | … ? … : … |
| 2 | 賦值 | 從右至左 | … = … |
| … += … | |||
| … -= … | |||
| … **= … | |||
| … *= … | |||
| … /= … | |||
| … %= … | |||
| … <<= … | |||
| … >>= … | |||
| … >>>= … | |||
| … &= … | |||
| … ^= … | |||
| … |= … | |||
| … &&= … | |||
| … ||= … | |||
| … ??= … | |||
| 1 | Comma / Sequence | 從左至右 | … , … |
This page was last modified on 2026年4月10日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.