1-js/02-first-steps/08-comparison#50
Conversation
|
@leviding 校对认领 |
Starriers
left a comment
There was a problem hiding this comment.
@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. | ||
| - 比较操作符始终返回逻辑值。 | ||
| - 字符串间按词典顺序逐字符比较大小。 |
| 我们为何要研究以上示例?我们需要时刻记得这些古怪的规则吗?不,并不需要。虽然这些规则随着使用都会烂熟于胸,但是我们需要遵循更为可靠的方法来避免潜在的问题。 | ||
|
|
||
| Just treat any comparison with `undefined/null` except the strict equality `===` with exceptional care. | ||
| 除了严格相等 `===` 外,其他凡是有 `undefined/null` 参与的比较,我们都需要额外 “关照”。 |
There was a problem hiding this comment.
原文没有着重强调,但如果想那么翻译,前面也不应该有空格
| 是的,上面的结果完全打破了你对数学的认识。在最后一行代码显示 "`null` 大于等于 0" 的情况下,前两行代码中一定会有一个是正确的,然而事实表明它们的结果都是 false。 | ||
|
|
||
| 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。 |
There was a problem hiding this comment.
手机上看的(1)前面是不是有空格,有的话是不需要的
| ``` | ||
|
|
||
| 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。 |
| `null/undefined` 的值会被转换为数字:`null` 转为 `0`,`undefined` 转为 `NaN`。 | ||
|
|
||
| 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. | ||
| 下面让我们看看,这些规则会带来什么有趣的现象。同时更重要的是,我们需要从中学会如何远离这些特性带来的 “陷阱”。 |
| ``` | ||
|
|
||
| There also exists a "strict non-equality" operator `!==`, as an analogy for `!=`. | ||
| 同样的,与 “不相等” 符号 `!=` 类似,“严格不相等” 表示为 `!==`。 |
| 同样的,与 “不相等” 符号 `!=` 类似,“严格不相等” 表示为 `!==`。 | ||
|
|
||
| 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. | ||
| 严格相等的操作符虽然略为冗长,但是它很清楚地显示了比较的意图,让你更少 “犯错”。 |
There was a problem hiding this comment.
让你更少犯错 =>降低你犯错的可能性。 或者你把空格去掉
| ## 字符串间的比较 | ||
|
|
||
| To see which string is greater than the other, the so-called "dictionary" or "lexicographical" order is used. | ||
| 在比较字符串的大小时,会使用 “字典” 或 “词典” 顺序进行判定。 |
There was a problem hiding this comment.
@leviding 麻烦看看这个 case。我翻阅了我翻译的或者其他人的翻译,存在为了照顾格式在 “” 前后添加空格的,也有不添加的,但是都通过了校对。你这边有无意见?
|
|
||
| - `true` -- means "yes", "correct" or "the truth". | ||
| - `false` -- means "no", "wrong" or "a lie". | ||
| - `true` —— 表示 “yes(是)”,“correct(正确)” 或 “the truth(真理)”。 |
There was a problem hiding this comment.
因为内容是译者自己加的,本来的纯英文引用,导致了混合中文。再用英文的引号,肯定不合适。所以我的想法是 应该用中文的,或者直接去掉自己的注释(这样的单词,对于开发者来说,如果不理解,个人建议是 —— 转行)。
| - 检测两个值的不等,在数学中使用 <code>≠</code> 符号,而在 JavaScript 中则通过在赋值符号前增加叹号表示:<code>a != b</code>。 | ||
|
|
||
| ## Boolean is the result | ||
| ## “比较” 终为 Boolean |
|
@leviding 校对认领~ |
|
@meloalright ok |
meloalright
left a comment
There was a problem hiding this comment.
@lcx-seima 出色的译者 + 出色的校对者楼上 我这边的建议不多啦
| - 检测两个值的不等,在数学中使用 <code>≠</code> 符号,而在 JavaScript 中则通过在赋值符号前增加叹号表示:<code>a != b</code>。 | ||
|
|
||
| ## Boolean is the result | ||
| ## “比较” 终为 Boolean |
There was a problem hiding this comment.
这里感觉可以直接意译就好了 =>『 比较结果为 Boolean 类型 』
|
@lcx-seima @leviding 校对完成 |
|
改完上面的就行了 |
|
@Starriers @meloalright 感谢细心校对 @leviding 已修改完 |
完成翻译 resolve #8