GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Nullish coalescing operator '??' by hiimchinh · Pull Request #125 · javascript-tutorial/vi.javascript.info

Conversation

@hiimchinh

@hiimchinh hiimchinh commented Mar 31, 2021

Copy link
Copy Markdown

No description provided.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@hiimchinh
final draft
a705d70
@javascript-translate-bot javascript-translate-bot added the review needed label Mar 31, 2021
@javascript-translate-bot
javascript-translate-bot requested a review from a team March 31, 2021 15:52
@javascript-translate-bot javascript-translate-bot mentioned this pull request Mar 31, 2021
Vietnamese Translation Progress #1
Open
@CLAassistant

CLAassistant commented Mar 31, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tunggnu
tunggnu reviewed Apr 2, 2021
View reviewed changes
Comment thread 1-js/02-first-steps/12-nullish-coalescing-operator/article.md
Comment on lines +5 to +7
Toán tử nullish coalescing được viết dưới dạng hai dấu hỏi `??`.

The nullish coalescing operator is written as two question marks `??`.
Do toán tử này coi `null` và `undefined` như nhau, chúng ta sẽ dùng một thuật ngữ đặc biệt ở bài này. Chúng ta sẽ nói rằng một biểu thức được coi là "được định nghĩa" khi nó không phải là `null` hoặc `undefined`.

@tunggnu tunggnu Apr 2, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Cần đảo lại thứ tự 2 đoạn này để đúng với bản gốc.
  • Do toán tử này coi null và undefined như nhau, chúng ta sẽ dùng một thuật ngữ đặc biệt ở bài này. => Câu này cung cấp thêm thông tin nhưng nó không có trong bản gốc. Liệu nên giữ nó lại hay bỏ đi?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@hiimchinh hiimchinh Apr 5, 2021

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

em thấy là ở bản gốc tiếng anh có thay đổi khác với bản hiện tại tiếng việt nên em đã dịch theo bản mới luôn ạ.
https://javascript.info/nullish-coalescing-operator

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@tunggnu tunggnu Apr 5, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Trên nguyên tắc, do bạn fork từ repo của bản tiếng Việt nên cần căn cứ theo bản tiếng Việt để dịch, không nên tham khảo chéo sang repo của bản tiếng Anh dù có thể nó có code mới hơn, nếu không nội dung sẽ không nhất quán, gây hiểu nhầm khi review.
  • Bạn nên tạo riêng một branch ứng với bài viết bạn đang dịch, và chỉ xóa nó sau khi đã merge thành công vào repo bản tiếng Việt, như thế bạn có thể dịch song song nhiều bài viết. Không nên làm việc trực tiếp trên branch master như với bài viết này.
  • Trong quá trình dịch hoặc trước khi bạn tạo pull request bạn có thể update repo của bản tiếng Việt rồi merge sang branch đang dịch để xem các thay đổi mới nhất nếu có, rồi cập nhật bản dịch của bạn nếu cần.

Mình đã update code mới nhất từ repo tiếng Anh sang repo tiếng Việt, do đó pull request này của bạn đã bị conflict. Bạn có thể cập nhật bản dịch này và xử lý conflict nếu muốn.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 1-js/02-first-steps/12-nullish-coalescing-operator/article.md

```js
result = (a !== null && a !== undefined) ? a : b;
result = a !== null && a !== undefined ? a : b;

@tunggnu tunggnu Apr 2, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Không sửa phần mã của bản gốc, trừ khi nó là chuỗi kí tự hoặc chú thích.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 1-js/02-first-steps/12-nullish-coalescing-operator/article.md
Comment on lines +24 to 25
Giờ thì chắc bạn đã biết rõ toán tử `??` làm gì. Hãy xem có thể áp dụng toán tử này ở đâu.

@tunggnu tunggnu Apr 2, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Đoạn này không có trong bản gốc.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 1-js/02-first-steps/12-nullish-coalescing-operator/article.md
```

Of course, if `user` had any value except `null/undefined`, then we would see it instead:
Còn dưới đây là ví dụ với `user` được gán với một cái tên:

@tunggnu tunggnu Apr 2, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dịch không giống bản gốc.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 1-js/02-first-steps/12-nullish-coalescing-operator/article.md
```

We can also use a sequence of `??` to select the first value from a list that isn't `null/undefined`.
Chúng ta cũng có thể dùng nhiều toán tử `??` để chọn giá trị đầu tiên trong một danh sách mà không có giá trị là `null/undefined`.

@tunggnu tunggnu Apr 2, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sửa câu này lại như sau liệu có hợp lý hơn?

Chúng ta cũng có thể dùng nhiều toán tử ?? để chọn giá trị đầu tiên không phải là null/undefined trong một danh sách.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 1-js/02-first-steps/12-nullish-coalescing-operator/article.md
- Còn biểu thức `height ?? 100` kiểm tra xem `height` có phải là `null/undefined` hay không, và nó không phải,
- thế nên kết quả của biểu thức là `height`, tức là `0`.

Trong thực tiễn, height là 0 thường là một giá trị hợp lệ và không nên thay thế bằng một giá trị mặc định. Vì thế ở đây sử dụng `??` là chính xác.

@tunggnu tunggnu Apr 2, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dịch không giống bản gốc.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 1-js/02-first-steps/12-nullish-coalescing-operator/article.md
Comment on lines +111 to +113
Thứ tự thực hiện cảu toán tử `??` gần ngang với `||`, chỉ thấp hơn một chút. Nó xếp thứ 5 trong [bảng MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#Table), trong khi `||` xếp thứ 6.

The precedence of the `??` operator is rather low: `5` in the [MDN table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#Table). So `??` is evaluated before `=` and `?`, but after most other operations, such as `+`, `*`.
Điều đó có nghĩa là, giống như `||`, toán tử nullish coaslescing `??` sẽ được đánh giá trước `=` và `?`, nhưng sau phần lớn các toán tử khác, ví dụ như `+`, `*`.

@tunggnu tunggnu Apr 2, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hai đoạn này tuy không sai nhưng không giống bản gốc nên cần dịch lại để tôn trọng bản gốc.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 1-js/02-first-steps/12-nullish-coalescing-operator/article.md
Điều đó có nghĩa là, giống như `||`, toán tử nullish coaslescing `??` sẽ được đánh giá trước `=` và `?`, nhưng sau phần lớn các toán tử khác, ví dụ như `+`, `*`.

So if we'd like to choose a value with `??` in an expression with other operators, consider adding parentheses:
Thế nên nếu chúng ta muốn sử dụng `??` trong một biểu thức với các toán tử khác, thì việc cho thêm ngoặc đơn nên được cân nhắc:

@tunggnu tunggnu Apr 2, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trong tình huống thông thường nên sử dụng câu chủ động thì tốt hơn là câu bị động, ví dụ như:

Thế nên nếu chúng ta muốn sử dụng ?? trong một biểu thức với các toán tử khác, thì nên cân nhắc cho thêm các dấu ngoặc đơn:

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 1-js/02-first-steps/12-nullish-coalescing-operator/article.md
let area = height ?? 100 * width ?? 50;

// ...works the same as this (probably not what we want):
// ... hoạt động tương đương như với dòng sau (có lẽ không như chúng ta mong muốn):

@tunggnu tunggnu Apr 2, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hoạt động tương đương như với dòng sau

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 1-js/02-first-steps/12-nullish-coalescing-operator/article.md
Vì lý do an toàn, Javascript cấm sử dụng `??` chung với toán tử `&&` và `||`, trừ khi thứ tự thực hiện được chỉ rõ với ngoặc đơn.

The code below triggers a syntax error:
Dòng code dưới đây gây ra một syntax error (lỗi cú pháp):

@tunggnu tunggnu Apr 2, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cụm từ "syntax error" trong tình huống này không phải là một thuật ngữ hoặc danh từ riêng được sử dụng nhiều lần trong bài viết, nên nó chỉ có tác dụng ghi chú về mặt dịch thuật. Cho nó vào trong cặp ngoặc đơn có lẽ hợp lý hơn:

Dòng code dưới đây gây ra một lỗi cú pháp (syntax error):

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@henryonsoftware

henryonsoftware commented Feb 23, 2023

Copy link
Copy Markdown
Contributor

@tunggnu Có nên đóng PR này không, outdated quá rồi, chắc bạn dịch không update đâu

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tunggnu

tunggnu commented Feb 23, 2023

Copy link
Copy Markdown
Contributor

@henryonsoftware Đóng PR này lại là hợp lý.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tunggnu tunggnu closed this Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@tunggnu tunggnu tunggnu left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

review needed

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@hiimchinh @CLAassistant @henryonsoftware @tunggnu @javascript-translate-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.