blob: af5ca56da092acea8b91d68390d4f503ef616a73 (
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/Left_shift_assignment
tags:
- Assignment operator
- JavaScript
- Language feature
- Operator
- Reference
browser-compat: javascript.operators.left_shift_assignment
---
{{jsSidebar("Operators")}}
左移赋值运算符 (`<<=`) 将变量向左移动指定数量的位,并将结果赋值给变量。
{{EmbedInteractiveExample("pages/js/expressions-left-shift-assignment.html")}}
## 语法
```js
x <<= y // x = x << y
```
## 例子
### 使用左移赋值
```js
let a = 5;
// 00000000000000000000000000000101
a <<= 2; // 20
// 00000000000000000000000000010100
```
## 规范
{{Specifications}}
## 浏览器兼容性
{{Compat("javascript.operators.left_shift_assignment")}}
## 参考
- [JS 指南中的赋值运算符](/zh-CN/docs/Web/JavaScript/Guide/Expressions_and_Operators#assignment)
- [左移运算符](/zh-CN/docs/Web/JavaScript/Reference/Operators/Left_shift)
|