Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1-js/02-first-steps/08-comparison #50

Conversation

lcx-seima
Copy link
Contributor

完成翻译 resolve #8

@Starriers
Copy link
Contributor

@leviding 校对认领

Copy link
Contributor

@Starriers Starriers left a comment

Choose a reason for hiding this comment

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

@lcx-seima @leviding 校对完成

- Values `null` and `undefined` equal `==` each other and do not equal any other value.
- Be careful when using comparisons like `>` or `<` with variables that can occasionally be `null/undefined`. Making a separate check for `null/undefined` is a good idea.
- 比较操作符始终返回逻辑值。
- 字符串间按词典顺序逐字符比较大小。
Copy link
Contributor

Choose a reason for hiding this comment

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

字典 加引号 !可以尊重一波原文


Just treat any comparison with `undefined/null` except the strict equality `===` with exceptional care.
除了严格相等 `===` 外,其他凡是有 `undefined/null` 参与的比较,我们都需要额外 “关照”。
Copy link
Contributor

Choose a reason for hiding this comment

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

原文没有着重强调,但如果想那么翻译,前面也不应该有空格


The reason is that an equality check `==` and comparisons `> < >= <=` work differently. Comparisons convert `null` to a number, hence treat it as `0`. That's why (3) `null >= 0` is true and (1) `null > 0` is false.
为什么会出现这种反常结果,这是因为相等性检测 `==` 和普通比较符 `> < >= <=` 的代码逻辑是相互独立的。进行值的比较会把 `null` 转为数字,因此它被转为了 `0`。这就是为什么(3)中 `null >= 0` 返回 true,(1)中 `null > 0` 返回 false
Copy link
Contributor

Choose a reason for hiding this comment

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

手机上看的(1)前面是不是有空格,有的话是不需要的


```js run
alert( null > 0 ); // (1) false
alert( null == 0 ); // (2) false
alert( null >= 0 ); // (3) *!*true*/!*
```

Yeah, mathematically that's strange. The last result states that "`null` is greater than or equal to zero". Then one of the comparisons above must be correct, but they are both false.
是的,上面的结果完全打破了你对数学的认识。在最后一行代码显示 "`null` 大于等于 0" 的情况下,前两行代码中一定会有一个是正确的,然而事实表明它们的结果都是 false
Copy link
Contributor

Choose a reason for hiding this comment

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

引号中包含了中文,所以换中文的


Now let's see funny things that happen when we apply those rules. And, what's more important, how to not fall into a trap with these features.
下面让我们看看,这些规则会带来什么有趣的现象。同时更重要的是,我们需要从中学会如何远离这些特性带来的 “陷阱”。
Copy link
Contributor

Choose a reason for hiding this comment

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

陷阱不要加空格

```

There also exists a "strict non-equality" operator `!==`, as an analogy for `!=`.
同样的,与 “不相等” 符号 `!=` 类似,“严格不相等” 表示为 `!==`。
Copy link
Contributor

@Starriers Starriers Apr 23, 2018

Choose a reason for hiding this comment

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

不相等 前后不要空格

Copy link
Contributor

Choose a reason for hiding this comment

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

后面同理


The strict equality check operator is a bit longer to write, but makes it obvious what's going on and leaves less space for errors.
严格相等的操作符虽然略为冗长,但是它很清楚地显示了比较的意图,让你更少 “犯错”。
Copy link
Contributor

Choose a reason for hiding this comment

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

让你更少犯错 =>降低你犯错的可能性。 或者你把空格去掉


To see which string is greater than the other, the so-called "dictionary" or "lexicographical" order is used.
在比较字符串的大小时,会使用 “字典” 或 “词典” 顺序进行判定。
Copy link
Contributor

Choose a reason for hiding this comment

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

这两个引号都不要前后空格

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@leviding 麻烦看看这个 case。我翻阅了我翻译的或者其他人的翻译,存在为了照顾格式在 “” 前后添加空格的,也有不添加的,但是都通过了校对。你这边有无意见?

Copy link
Member

Choose a reason for hiding this comment

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

@lcx-seima 引号里内容是中文的则不加空格,为英文则加空格。之前没有太注意这个问题。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@leviding 好的,可以更新这条rule到wiki

Copy link
Member

Choose a reason for hiding this comment

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

@lcx-seima 好,感谢提醒 😆


- `true` -- means "yes", "correct" or "the truth".
- `false` -- means "no", "wrong" or "a lie".
- `true` —— 表示 “yes(是)”,“correct(正确)” 或 “the truth(真理)”。
Copy link
Contributor

Choose a reason for hiding this comment

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

包含了中文用中文引号 下文同理

Copy link
Member

Choose a reason for hiding this comment

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

这里译者用的是中文引号了吧

Copy link
Contributor

Choose a reason for hiding this comment

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

因为内容是译者自己加的,本来的纯英文引用,导致了混合中文。再用英文的引号,肯定不合适。所以我的想法是 应该用中文的,或者直接去掉自己的注释(这样的单词,对于开发者来说,如果不理解,个人建议是 —— 转行)。

Copy link
Member

@leviding leviding Apr 23, 2018

Choose a reason for hiding this comment

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

@Starriers 此处译者用的引号已经是中文的引号了,你认真看看,我明白你的意思。

Copy link
Member

Choose a reason for hiding this comment

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

这儿就这样吧,这一行不用改,其他的校对意见照常修改。


## Boolean is the result
## “比较” 终为 Boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

比较值为 Boolean 类型 或者你去掉空格

@meloalright
Copy link

@leviding 校对认领~

@leviding
Copy link
Member

@meloalright ok

Copy link

@meloalright meloalright left a comment

Choose a reason for hiding this comment

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

@lcx-seima 出色的译者 + 出色的校对者楼上 我这边的建议不多啦


## Boolean is the result
## “比较” 终为 Boolean
Copy link

Choose a reason for hiding this comment

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

这里感觉可以直接意译就好了 =>『 比较结果为 Boolean 类型 』

@meloalright
Copy link

@lcx-seima @leviding 校对完成

@leviding
Copy link
Member

改完上面的就行了

@lcx-seima
Copy link
Contributor Author

@Starriers @meloalright 感谢细心校对

@leviding 已修改完

@leviding leviding merged commit a36aa33 into javascript-tutorial:zh-hans Apr 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants