# 運算子優先序

## 相依性(Associativity)

```a OP b OP c
```

```a = b = 5;
```

`a``b` 的預期結果為 5，因為賦值運算符 (Assignment operator) 為右相依性，因此從右至左返回值。一開始 `b` 被設定為 5，接著 `a` 也被設定為 5。

## 表格(Table)

Precedence

Operator type

Associativity

Individual operators
20 `Grouping` `( … )`
19 `Member Access` 從左至右 `… . …`
`Computed Member Access` 從左至右 `… [ … ]`
`new` (with argument list) `new … ( … )`
Function Call 從左至右 `… ( … )`
18 `new` (without argument list) 從右至左 `new …`
17 `Postfix Increment` `… ++`
`Postfix Decrement` `… --`
16 Logical NOT 從右至左 `! …`
Bitwise NOT `~ …`
Unary Plus `+ …`
Unary Negation `- …`
Prefix Increment `++ …`
Prefix Decrement `-- …`
typeof `typeof …`
void `void …`
delete `delete …`
await `await …`
15 Exponentiation 從右至左 `… ** …`
14 Multiplication 從左至右 `… * …`
Division `… / …`
Remainder `… % …`
13 Addition 從左至右 `… + …`
Subtraction `… - …`
12 Bitwise Left Shift 從左至右 `… << …`
Bitwise Right Shift `… >> …`
Bitwise Unsigned Right Shift `… >>> …`
11 Less Than 從左至右 `… < …`
Less Than Or Equal `… <= …`
Greater Than `… > …`
Greater Than Or Equal `… >= …`
in `… in …`
instanceof `… instanceof …`
10 Equality 從左至右 `… == …`
Inequality `… != …`
Strict Equality `… === …`
Strict Inequality `… !== …`
9 Bitwise AND 從左至右 `… & …`
8 Bitwise XOR 從左至右 `… ^ …`
7 Bitwise OR 從左至右 `… | …`
6 Logical AND 從左至右 `… && …`
5 Logical OR 從左至右 `… || …`
4 Conditional 從右至左 `… ? … : …`
3 Assignment 從右至左 `… = …`
`… += …`
`… -= …`
`… **= …`
`… *= …`
`… /= …`
`… %= …`
`… <<= …`
`… >>= …`
`… >>>= …`
`… &= …`
`… ^= …`
`… |= …`
2 yield 從右至左 `yield …`
yield* `yield* …`
1 Comma / Sequence 從左至右 `… , …`