-
Notifications
You must be signed in to change notification settings - Fork 1.2k
1-02-11-逻辑运算符 #55
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-02-11-逻辑运算符 #55
Conversation
@leviding 翻译完成 |
@leviding 校对认领 |
@wavezhang ok |
@@ -1,13 +1,13 @@ | |||
The answer: first `1`, then `2`. | |||
答案:第一个是 `1`,然后是 `2`。 |
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.
这里 first... then...
翻译成 首先……然后……
是不是更合理一点?
1. The first OR `||` evaluates it's left operand `alert(1)`. That shows the first message with `1`. | ||
2. The `alert` returns `undefined`, so OR goes on to the second operand searching for a truthy value. | ||
3. The second operand `2` is truthy, so the execution is halted, `2` is returned and then shown by the outer alert. | ||
1. 第一个或运算 `||` 对它左边的 `alert(1)` 进行了计算。这就显示了第一条 `1` 的信息。 |
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.
operand
直接忽略不太好吧,可以翻译成左值
2. The `alert` returns `undefined`, so OR goes on to the second operand searching for a truthy value. | ||
3. The second operand `2` is truthy, so the execution is halted, `2` is returned and then shown by the outer alert. | ||
1. 第一个或运算 `||` 对它左边的 `alert(1)` 进行了计算。这就显示了第一条 `1` 的信息。 | ||
2. 函数 `alert` 返回了 `undefined`,所以或运算继续检查第二个参数,寻找真值。 |
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.
这里operand
翻译成参数
不太准确,应该翻译成操作数
|
||
--- | ||
|
||
# What is the result of AND'ed alerts? | ||
# 与运算和 alerts 的结果是什么? |
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.
这样会不会好点?
# 与运算连接的alerts结果是什么?
|
||
In JavaScript the operator is a little bit more tricky and powerful. But first let's see what happens with boolean values. | ||
在 JavaScript 中,逻辑运算符更加灵活强大。但是首先我们来看一下参与运算的布尔值发生了什么。 |
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.
但是我们首先看下操作数是布尔值的时候发生了什么。
|
||
In other words, a chain of OR `"||"` returns the first truthy value or the last one if no such value is found. | ||
也就是,一个或 `"||"` 运算的链将返回第一个真(布尔转化后为 true 的,译者注)值,如果这样的值不存在就返回该链的最后一个值。 |
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.
这个不需要注吧?
``` | ||
|
||
If both `currentUser` and `defaultUser` were falsy then `"unnamed"` would be the result. | ||
2. **Short-circuit evaluation.** | ||
如果 `currentUser` 和 `defaultUser` 都是无效值,那么结果就是 `"unnamed"`。 |
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.
falsy
翻译成假值
好点?
|
||
This is clearly seen when the expression given as the second argument has a side effect. Like a variable assignment. | ||
当表达式作为第二个参数并且有一定副作用 - 比如变量赋值 - 的时候,这就清楚可见了。 |
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.
不需要连词符吧?
|
||
The AND operator is represented with two ampersands `&&`: | ||
两个 & 符号表示 `&&` 与操作: |
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.
这个得用半角符号吧
|
||
In other words, AND returns the first falsy value or the last value if none were found. | ||
换句话说,与操作符返回第一个假值,如果没有假值就返回最后一个值。(假值:将该变量进行布尔转换后为 `false`。译者注) |
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.
是不是也不需要注
@EmilyQiRabbit @leviding 校对完成 |
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.
不错,进步很大
@@ -1,10 +1,10 @@ | |||
importance: 3 | |||
重要性:3 |
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.
不翻译
@@ -1,10 +1,10 @@ | |||
importance: 5 | |||
重要性:5 |
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.
不翻译
@@ -1,10 +1,10 @@ | |||
importance: 5 | |||
重要性:5 |
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.
不翻译
|
||
Because of that, `&&` evaluates the left operand (outputs `1`), and immediately stops, because `undefined` is a falsy value. And `&&` looks for a falsy value and returns it, so it's done. | ||
因此,`&&` 计算了它左边的操作数(显示 `1`),然后立即停止了,因为 `undefined` 是一个假值。并且 `&&` 就是寻找假值然后返回它,所以运算结束。 |
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.
显示 1
的括号用中文的
@@ -1,10 +1,10 @@ | |||
importance: 3 | |||
重要性:3 |
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.
不翻译
@@ -1,9 +1,9 @@ | |||
importance: 3 | |||
重要性:3 |
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.
不翻译
// Doesn't run | ||
// -1 && 0 = 0, falsy | ||
// 不执行。 | ||
// -1 && 0 = 0, 假值 |
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.
逗号用全角,假值前多于一个空格
@@ -1,12 +1,12 @@ | |||
importance: 5 | |||
重要性:5 |
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.
不翻译
|
||
--- | ||
|
||
# A question about "if" | ||
# 一个关于“if”的问题 |
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.
"if" 前后需要空格,且本 Repo 中就用英文的引号吧
- Evaluate operands from left to right. | ||
- For each operand, convert it to a boolean. If the result is `false`, stop and return the original value of that operand. | ||
- If all other operands have been assessed (i.e. all were truthy), return the last operand. | ||
=- 从左到右依次计算操作数。 |
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.
开头手误多打了一个等于号?
@leviding 校对完成 |
翻译完成 #11