JavaScript 运算符优先级
运算符优先级描述操作的执行顺序 算术表达式。
乘法 (*) 和除法 (/) 的优先级高于加法 (+) 和减法 (-)。
1 | let x = 100 + 50 * 3; |
1 | let x = (100 + 50) * 3; |
1 | let x = 100 / 50 * 3; |
运算符优先级值 | |||
---|---|---|---|
括号中的表达式是在表达式的其余部分执行函数之前计算的,然后再在表达式的其余部分中使用结果 | |||
Val | 算子 | 描述 | 例 |
| 18 | ( )
| | (100 + 50) * 3
|
| 17 | .
| | person.name
|
| 17 | []
| | person[“name”]
|
| 17 | ?.
| ES2020 | x ?.y
|
| 17 | ()
| | myFunction()
|
| 17 | new
| | new Date("June 5,2022")
|
| 16 | new
| | new Date()
|
| 递增运算符 | | | |
| 后缀递增在前缀递增之前执行 | | | |
| 15 | ++
| | i++
|
| 15 | --
| | i--
|
| 14 | ++
| | ++i
|
| 14 | --
| | --i
|
| NOT 运算符 | | | |
| 14 | !
| | !(x==y)
|
| 14 | ~
| | ~x
|
| 一元运算符 | | | |
| 14 | +
| | +x
|
| 14 | -
| | -x
|
| 14 | typeof
| | typeof x
|
| 14 | void
| | void(0)
|
| 14 | delete
| | delete myCar.color
|
| 算术运算符 | | | |
| 在乘法之前执行幂 | | | |
| 乘法和除法在加法和减法之前执行 | | | |
| 13 | **
| ES2016 | 10 ** 2
|
| 12 | *
| | 10 * 5
|
| 12 | /
| | 10/5
|
| 12 | %
| | 10 % 5
|
| 11 | +
| | 10 + 5
|
| 11 | -
| | 10-5
|
| 11 | +
| | "John" + "Doe"
|
| 操作符 | | | |
| 10 | <<
| | x << 2
|
| 10 | >>
| | x >> 2
|
| 10 | >>>
| | x >>> 2
|
| 关系运算符 | | | |
| 9 | in
| | "PI" in Math
|
| 9 | instanceof
| | x instanceof Array
|
| 比较运算符 | | | |
| 9 | <
| | x < y
|
| 9 | <=
| | x <= y
|
| 9 | >
| | x > y
|
| 9 | >=
| | x >= Array
|
| 8 | ==
| | x == y
|
| 8 | ===
| | x === y
|
| 8 | !=
| | x != y
|
| 8 | !==
| | x !== y
|
| 按位运算符 | | | |
| 7 | &
| | X & Y
|
| 6 | ^
| | x ^ y
|
| 5 | \|
| | x \|y
|
| 逻辑运算符 | | | |
| 4 | &&
| | x & & y
|
| 3 | \||
| | x \|| y
|
| 3 | ??
| ES2020 | x ??y
|
| 条件(三元)运算符 | | | |
| 2 | ?:
| | ? "yes" : "no"
|
| 赋值运算符 | | | |
| 赋值在其他操作之后执行 | | | |
| 2 | =
| | x = y
|
| 2 | :
| | x:5
|
| 2 | +=
| | x += y
|
| 2 | -=
| | x -= y
|
| 2 | *=
| | x *= y
|
| 2 | **=
| | x **= y
|
| 2 | /=
| | x /= y
|
| 2 | %=
| | x %= y
|
| 2 | <<=
| | x <<= y
|
| 2 | >>=
| | x >>= y
|
| 2 | >>>=
| | x >>>= y
|
| 2 | &=
| | x &= y
|
| 2 | \|=
| | x \|= y
|
| 2 | ^=
| | x ^= y
|
| 2 | &&=
| | x &&= y
|
| 2 | `|= | <a class="try_button" style="display:none;" title="赋值运算符" href="javascript:openTry('/examples/other/javascript/Precedence/64.html','Precedence')">逻辑 OR 分配</a> |
x |= y` |
| 2 | =>
| | x => y
|
| 2 | yield
| 暂停/恢复 | yield x
|
| 2 | yield*
| 代表 | yield* x
|
| 2 | ...
| | ...x
|
| 1 | ,
| 逗号 | x , y
|
0评论