change var to const and let (#23151)
* change var to const and let * fix: output
This commit is contained in:
committed by
Huyen Nguyen
parent
7d226d0078
commit
6814ad7f67
@ -32,26 +32,26 @@ The `for...of` statement creates a loop iterating over iterable objects (includi
|
|||||||
|
|
||||||
### Map
|
### Map
|
||||||
```javascript
|
```javascript
|
||||||
var m = new Map();
|
const m = new Map();
|
||||||
m.set(1, "black");
|
m.set(1, "black");
|
||||||
m.set(2, "red");
|
m.set(2, "red");
|
||||||
|
|
||||||
for (var n of m) {
|
for (let n of m) {
|
||||||
console.log(n);
|
console.log(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 1,black
|
// [1, "black"]
|
||||||
// 2,red
|
// [2, "red"]
|
||||||
```
|
```
|
||||||
|
|
||||||
### Set
|
### Set
|
||||||
```javascript
|
```javascript
|
||||||
var s = new Set();
|
const s = new Set();
|
||||||
s.add(1);
|
s.add(1);
|
||||||
s.add("red");
|
s.add("red");
|
||||||
|
|
||||||
for (var n of s) {
|
for (let n of s) {
|
||||||
console.log(n);
|
console.log(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user