Skip to content

Commit 349df39

Browse files
committed
translate next 10 question (112-121) into Vietnamese
1 parent f427846 commit 349df39

File tree

1 file changed

+39
-35
lines changed

1 file changed

+39
-35
lines changed

vi-VI/README-vi.md

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3570,7 +3570,7 @@ getName() // Lydia
35703570

35713571
---
35723572

3573-
###### 112. What's the output?
3573+
###### 112. Output là gì?
35743574

35753575
```javascript
35763576
function* generatorOne() {
@@ -3598,16 +3598,16 @@ console.log(two.next().value)
35983598

35993599
#### Đáp án: C
36003600

3601-
With the `yield` keyword, we `yield` values in a generator function. With the `yield*` keyword, we can yield values from another generator function, or iterable object (for example an array).
3601+
Với từ khóa `yield`, ta sẽ trả về các giá trị trong một `generator`. Với từ khóa `yield*`, ta có thể trả về giá trị từ một `engerator` khác, hoặc một `iterable object` (ví dụ mảng).
36023602

3603-
In `generatorOne`, we yield the entire array `['a', 'b', 'c']` using the `yield` keyword. The value of `value` property on the object returned by the `next` method on `one` (`one.next().value`) is equal to the entire array `['a', 'b', 'c']`.
3603+
Trong `generatorOne`, ta trả về toàn bộ mảng `['a', 'b', 'c']` sử dụng từ khóa `yield`. Giá trị của thuộc tính `value` trong object thu được bởi phương thức `next` trong `one` (`one.next().value`) là toàn bộ mảng `['a', 'b', 'c']`.
36043604

36053605
```javascript
36063606
console.log(one.next().value) // ['a', 'b', 'c']
36073607
console.log(one.next().value) // undefined
36083608
```
36093609

3610-
In `generatorTwo`, we use the `yield*` keyword. This means that the first yielded value of `two`, is equal to the first yielded value in the iterator. The iterator is the array `['a', 'b', 'c']`. The first yielded value is `a`, so the first time we call `two.next().value`, `a` is returned.
3610+
Trong `generatorTwo`, ta sử dụng từ khóa `yield*`. Có nghĩa là giá trị đầu tiên mà `two` trả về là giá trị đầu tiên trong `iterator`. Trong trường hợp này `iterator` của chúng ta là mảng `['a', 'b', 'c']`. Giá trị đầu tiên của mảng là `a`, nên lần đầu tiên khi ta gọi `two.next().value`, `a` sẽ được trả về.
36113611

36123612
```javascript
36133613
console.log(two.next().value) // 'a'
@@ -3621,7 +3621,7 @@ console.log(two.next().value) // undefined
36213621

36223622
---
36233623

3624-
###### 113. What's the output?
3624+
###### 113. Output là gì?
36253625

36263626
```javascript
36273627
console.log(`${(x => x)('I love')} to program`)
@@ -3637,14 +3637,14 @@ console.log(`${(x => x)('I love')} to program`)
36373637

36383638
#### Đáp án: A
36393639

3640-
Expressions within template literals are evaluated first. This means that the string will contain the returned value of the expression, the immediately invoked function `(x => x)('I love')` in this case. We pass the value `'I love'` as an argument to the `x => x` arrow function. `x` is equal to `'I love'`, which gets returned. This results in `I love to program`.
3640+
Biểu thức bên trong chuỗi template (tức chuỗi nằm trong hai dấu ``, gọi là `template literals`) sẽ được đánh giá trước. Sau đó kết quả của biểu thức sẽ được đưa vào chuỗi, trong trường hợp này biểu thức là `(x => x)('I love')`. Chúng ta truyền giá trị đối số `'I love'` cho một arrow function `x => x`. `x` lúc này là `'I love'`, và trả về chính nó. Cuối cùng kết quả của chuỗi là `I love to program`.
36413641

36423642
</p>
36433643
</details>
36443644

36453645
---
36463646

3647-
###### 114. What will happen?
3647+
###### 114. Điều gì sẽ xảy ra?
36483648

36493649
```javascript
36503650
let config = {
@@ -3656,24 +3656,24 @@ let config = {
36563656
config = null
36573657
```
36583658

3659-
- A: The `setInterval` callback won't be invoked
3660-
- B: The `setInterval` callback gets invoked once
3661-
- C: The `setInterval` callback will still be called every second
3662-
- D: We never invoked `config.alert()`, config is `null`
3659+
- A: Callback `setInterval` sẽ không được gọi
3660+
- B: Callback `setInterval` sẽ được gọi một lần duy nhất
3661+
- C: Callback `setInterval` vẫn sẽ được gọi mỗi giây một lần
3662+
- D: `config.alert()` không bao giờ được gọi bởi config `null`
36633663

36643664
<details><summary><b>Đáp án</b></summary>
36653665
<p>
36663666

36673667
#### Đáp án: C
36683668

3669-
Normally when we set objects equal to `null`, those objects get _garbage collected_ as there is no reference anymore to that object. However, since the callback function within `setInterval` is an arrow function (thus bound to the `config` object), the callback function still holds a reference to the `config` object. As long as there is a reference, the object won't get garbage collected. Since it's not garbage collected, the `setInterval` callback function will still get invoked every 1000ms (1s).
3669+
Thông thường khi ta set một object bằng `null`, thì object này sẽ được bộ dọn rác dọn đi do không còn gì reference đến nó nữa (_garbage collected_). Tuy nhiên, do callback trong `setInterval` là một arrow function (do đó nó sẽ gắn với object `config`), nên callback này vẫn sẽ giữ reference đến object `config`. Vì vẫn còn giữ reference, nên object sẽ không bị dọn đi. Do đó nó vẫn sẽ được gọi sau mỗi 1000ms (tức 1 giây).
36703670

36713671
</p>
36723672
</details>
36733673

36743674
---
36753675

3676-
###### 115. Which method(s) will return the value `'Hello world!'`?
3676+
###### 115. Những hàm nào sẽ trả về `'Hello world!'`?
36773677

36783678
```javascript
36793679
const myMap = new Map()
@@ -3691,25 +3691,25 @@ myMap.get(() => 'greeting')
36913691

36923692
- A: 1
36933693
- B: 2
3694-
- C: 2 and 3
3695-
- D: All of them
3694+
- C: 2 3
3695+
- D: Tất cả
36963696

36973697
<details><summary><b>Đáp án</b></summary>
36983698
<p>
36993699

37003700
#### Đáp án: B
37013701

3702-
When adding a key/value pair using the `set` method, the key will be the value of the first argument passed to the `set` function, and the value will be the second argument passed to the `set` function. The key is the _function_ `() => 'greeting'` in this case, and the value `'Hello world'`. `myMap` is now `{ () => 'greeting' => 'Hello world!' }`.
3702+
Khi ta thêm vào một cặp key/value với từ khóa `set`, key sẽ là đối số đầu tiên đưa vào trong hàm `set` function, value sẽ là đối số thứ hai.Trong trường hơp này key chính là _hàm_ `() => 'greeting'`, value `'Hello world'`. `myMap` trở thành `{ () => 'greeting' => 'Hello world!' }`.
37033703

3704-
1 is wrong, since the key is not `'greeting'` but `() => 'greeting'`.
3705-
3 is wrong, since we're creating a new function by passing it as a parameter to the `get` method. Object interact by _reference_. Functions are objects, which is why two functions are never strictly equal, even if they are identical: they have a reference to a different spot in memory.
3704+
1 sai, vì key `() => 'greeting'` chứ không phải là `'greeting'`.
3705+
3 sai, vì khi chúng ta đưa một hàm vào làm đối số trong phương thức `get`, nó sẽ được đưa vào dưới dạng _reference_. Function vốn là object, do đó 2 hàm sẽ không bao giờ là `strictly equal`, mặc dù chúng có trông giống nhau đi chăng nữa thì chúng vẫn trỏ đến các vùng nhớ khác nhau.
37063706

37073707
</p>
37083708
</details>
37093709

37103710
---
37113711

3712-
###### 116. What's the output?
3712+
###### 116. Output là gì?
37133713

37143714
```javascript
37153715
const person = {
@@ -3739,18 +3739,18 @@ console.log(person)
37393739

37403740
#### Đáp án: C
37413741

3742-
Both the `changeAge` and `changeAgeAndName` functions have a default parameter, namely a _newly_ created object `{ ...person }`. This object has copies of all the key/values in the `person` object.
3742+
Cả hai hàm `changeAge` `changeAgeAndName` đều có tham số mặc định - nó là một _bản copy_ mới của object `{ ...person }`. Object này sẽ copy tất cả những cặp key/values bên trong object `person`.
37433743

3744-
First, we invoke the `changeAge` function and pass the `person` object as its argument. This function increases the value of the `age` property by 1. `person` is now `{ name: "Lydia", age: 22 }`.
3744+
Đầu tiên, chúng ta gọi hàm `changeAge` và đưa chính object `person` vào làm đối số. Hàm này sẽ tăng giá trị của thuộc tính `age` lên 1. `person` lúc này là `{ name: "Lydia", age: 22 }`.
37453745

3746-
Then, we invoke the `changeAgeAndName` function, however we don't pass a parameter. Instead, the value of `x` is equal to a _new_ object: `{ ...person }`. Since it's a new object, it doesn't affect the values of the properties on the `person` object. `person` is still equal to `{ name: "Lydia", age: 22 }`.
3746+
Sau đó, chúng ta gọi hàm `changeAgeAndName` tuy nhiên không đưa vào đối số nào cả. Do đó giá trị của `x` lúc này sẽ là giá trị mặc định, tức một bản _copy_ của object `{ ...person }`. Do nó chỉ là một bản copy (tức object mới), nên nó không ảnh hưởng gì tới giá trị của object `person` gốc, giá trị của `person` gốc sẽ vẫn là `{ name: "Lydia", age: 22 }`.
37473747

37483748
</p>
37493749
</details>
37503750

37513751
---
37523752

3753-
###### 117. Which of the following options will return `6`?
3753+
###### 117. Phép tính nào dưới đây trả về `6`?
37543754

37553755
```javascript
37563756
function sumValues(x, y, z) {
@@ -3768,14 +3768,14 @@ function sumValues(x, y, z) {
37683768

37693769
#### Đáp án: C
37703770

3771-
With the spread operator `...`, we can _spread_ iterables to individual elements. The `sumValues` function receives three arguments: `x`, `y` and `z`. `...[1, 2, 3]` will result in `1, 2, 3`, which we pass to the `sumValues` function.
3771+
Với toán tử ba chấm (`spread operator`) `...`, chúng ta có thể unpack một iterable thành từng các phần tử riêng biệt. Hàm `sumValues` nhận vào 3 giá trị: `x`, `y` `z`. `...[1, 2, 3]` sẽ trả về `1, 2, 3`, đưa vào `sumValues` sẽ cho ta kết quả là 6.
37723772

37733773
</p>
37743774
</details>
37753775

37763776
---
37773777

3778-
###### 118. What's the output?
3778+
###### 118. Output là gì?
37793779

37803780
```javascript
37813781
let num = 1;
@@ -3794,14 +3794,14 @@ console.log(list[(num += 1)]);
37943794

37953795
#### Đáp án: B
37963796

3797-
With the `+=` operand, we're incrementing the value of `num` by `1`. `num` had the initial value `1`, so `1 + 1` is `2`. The item on the second index in the `list` array is 🥰, `console.log(list[2])` prints 🥰.
3797+
Với phép toán `+=`, Ta tăng giá trị của `num` lên `1`. `num` có giá trị khởi tạo là `1`, do đó `1 + 1` `2`. Phần tử thứ hai của `list` 🥰, do đó `console.log(list[2])` sẽ in ra 🥰.
37983798

37993799
</p>
38003800
</details>
38013801

38023802
---
38033803

3804-
###### 119. What's the output?
3804+
###### 119. Output là gì?
38053805

38063806
```javascript
38073807
const person = {
@@ -3832,19 +3832,22 @@ console.log(member.getLastName?.());
38323832
38333833
#### Đáp án: B
38343834
3835-
With the optional chaining operator `?.`, we no longer have to explicitly check whether the deeper nested values are valid or not. If we're trying to access a property on an `undefined` or `null` value (_nullish_), the expression short-circuits and returns `undefined`.
3835+
Với phép toán optional chaining `?.`, chúng ta sẽ không cần phải check xem giá trị phía sau nó có được phép truy cập hay có tồn tại hay không. Nếu ta cố lấy một thuộc tính của `undefined` hay `null` (_nullish_), biểu thức sẽ dừng lại và trả về `undefined`.
38363836
3837-
`person.pet?.name`: `person` has a property named `pet`: `person.pet` is not nullish. It has a property called `name`, and returns `Mara`.
3838-
`person.pet?.family?.name`: `person` has a property named `pet`: `person.pet` is not nullish. `pet` does _not_ have a property called `family`, `person.pet.family` is nullish. The expression returns `undefined`.
3839-
`person.getFullName?.()`: `person` has a property named `getFullName`: `person.getFullName()` is not nullish and can get invoked, which returns `Lydia Hallie`.
3840-
`member.getLastName?.()`: `member` is not defined: `member.getLastName()` is nullish. The expression returns `undefined`.
3837+
`person.pet?.name`: `person` có thuộc tính `pet`: do đó `person.pet` không phải là một nullish. Nó có một thuộc tính `name`, với giá trị `Mara`.
3838+
3839+
`person.pet?.family?.name`: `person` có thuộc tính `pet`: do đó `person.pet` không phải là nullish. Tuy nhiên `pet` không có thuộc tính `family`, nên `person.pet.family` là nullish. Biểu thức sẽ trả về `undefined`.
3840+
3841+
`person.getFullName?.()`: `person` có thuộc tính `getFullName`: do đó `person.getFullName()` không phải nullish và có thể gọi ra, trả về `Lydia Hallie`.
3842+
3843+
`member.getLastName?.()`: `member` không được định nghĩa: do đó `member.getLastName()` là nullish. Biểu thức trả về `undefined`.
38413844
38423845
</p>
38433846
</details>
38443847
38453848
---
38463849
3847-
###### 120. What's the output?
3850+
###### 120. Ouput là gì?
38483851
38493852
```javascript
38503853
const groceries = ["banana", "apple", "peanuts"];
@@ -3866,14 +3869,14 @@ if (groceries.indexOf("banana")) {
38663869
38673870
#### Đáp án: B
38683871
3869-
We passed the condition `groceries.indexOf("banana")` to the if-statement. `groceries.indexOf("banana")` returns `0`, which is a falsy value. Since the condition in the if-statement is falsy, the code in the `else` block runs, and `We don't have to buy bananas!` gets logged.
3872+
Ta đưa một điều kiện `groceries.indexOf("banana")` vào câu lệnh `if`. `groceries.indexOf("banana")` trả về `0`, là một giá trị `falsy`. Do đó điệu kiện `if` sẽ chạy vào khối `else` và in ra `We don't have to buy bananas!`.
38703873
38713874
</p>
38723875
</details>
38733876
38743877
---
38753878
3876-
###### 121. What's the output?
3879+
###### 121. Ouput là gì?
38773880
38783881
```javascript
38793882
const config = {
@@ -3897,6 +3900,7 @@ console.log(config.language);
38973900
#### Đáp án: D
38983901
38993902
The `language` method is a `setter`. Setters don't hold an actual value, their purpose is to _modify_ properties. When calling a `setter` method, `undefined` gets returned.
3903+
Phương thức `language` là một `setter`. Setter không mang giá trị, nhiệm vụ của nó chỉ đơn giản là _thay đổi_ thuộc tính. Khi ta gọi một phương thức `setter` nó sẽ trả về `undefined`.
39003904

39013905
</p>
39023906
</details>

0 commit comments

Comments
 (0)