Skip to content

Commit 5bcb810

Browse files
author
Uyen Nguyen
committed
translate to Vietnamese lydiahallie#145
1 parent 570f2df commit 5bcb810

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

vi-VI/README-vi.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4706,3 +4706,35 @@ Mặc định ta không thể duyệt qua được object. Trừ phi nó đượ
47064706
47074707
</p>
47084708
</details>
4709+
4710+
###### 145. Output là gì?
4711+
4712+
```javascript
4713+
let count = 0;
4714+
const nums = [0, 1, 2, 3];
4715+
4716+
nums.forEach(num => {
4717+
if (num) count += 1
4718+
})
4719+
4720+
console.log(count)
4721+
```
4722+
4723+
- A: 1
4724+
- B: 2
4725+
- C: 3
4726+
- D: 4
4727+
4728+
<details><summary><b>Đáp án</b></summary>
4729+
<p>
4730+
4731+
#### Answer: C
4732+
4733+
The `if` condition within the `forEach` loop checks whether the value of `num` is truthy or falsy. Since the first number in the `nums` array is `0`, a falsy value, the `if` statement's code block won't be executed. `count` only gets incremented for the other 3 numbers in the `nums` array, `1`, `2` and `3`. Since `count` gets incremented by `1` 3 times, the value of `count` is `3`.
4734+
4735+
Câu lệnh `if` trong vòng lập `forEach` kiểm tra giá trị của `num` là truthy hay falsy. Vì số đầu tiên trong mảng `nums``0`, giá trị falsy, code trong câu lệnh `if` sẽ không chạy. `count` chỉ tăng giá trị đối với 3 số còn lại trong mảng `nums`, `1`, `2``3`. Vì giá trị của `count` tăng thêm `1` trong 3 lần, giá trị của `count` sẽ là `3`.
4736+
4737+
</p>
4738+
</details>
4739+
4740+
---

0 commit comments

Comments
 (0)