blob: 7afdf1311e06531abd68c844a8e4887ba12c355c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
---
title: 右移赋值 (>>=)
slug: Web/JavaScript/Reference/Operators/Right_shift_assignment
tags:
- Assignment operator
- JavaScript
- Language feature
- Operator
- Reference
browser-compat: javascript.operators.right_shift_assignment
---
{{jsSidebar("Operators")}}
右移赋值运算符 (`>>=`) 将变量向右移动指定数量的位,并将结果赋值给变量。
{{EmbedInteractiveExample("pages/js/expressions-right-shift-assignment.html")}}
## 语法
```js
x >>= y // x = x >> y
```
## 例子
### 使用右移赋值运算符
```js
let a = 5; // (00000000000000000000000000000101)
a >>= 2; // 1 (00000000000000000000000000000001)
let b = -5; // (-00000000000000000000000000000101)
b >>= 2; // -2 (-00000000000000000000000000000010)
```
## 规范
{{Specifications}}
## 浏览器兼容性
{{Compat}}
## 参考
- [JS 指南中的赋值运算符](/zh-CN/docs/Web/JavaScript/Guide/Expressions_and_Operators#assignment)
- [右移运算符](/zh-CN/docs/Web/JavaScript/Reference/Operators/Right_shift)
|