From 529597685116d6199ab8553f6393a994f3314ce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 12:50:47 +0800 Subject: [PATCH 01/41] Update article.md --- .../11-logical-operators/article.md | 178 +++++++++--------- 1 file changed, 89 insertions(+), 89 deletions(-) diff --git a/1-js/02-first-steps/11-logical-operators/article.md b/1-js/02-first-steps/11-logical-operators/article.md index 4ccb4fea62..56db2ea893 100644 --- a/1-js/02-first-steps/11-logical-operators/article.md +++ b/1-js/02-first-steps/11-logical-operators/article.md @@ -1,24 +1,24 @@ -# Logical operators +# 逻辑运算符 -There are three logical operators in JavaScript: `||` (OR), `&&` (AND), `!` (NOT). +JavaScript 里有三个逻辑运算符:`||` (或), `&&` (与), `!` (非)。 -Although they are called "logical", they can be applied to values of any type, not only boolean. The result can also be of any type. +虽然被称为“逻辑”,这些运算符却可以被应用于任意类型的值,而不仅仅是布尔值。结果也同样可能是任意类型。 -Let's see the details. +让我们来详细看一下。 -## || (OR) +## || (或) -The "OR" operator is represented with two vertical line symbols: +两个竖线符号表示了“或”运算: ```js result = a || b; ``` -In classical programming, logical OR is meant to manipulate boolean values only. If any of its arguments are `true`, then it returns `true`, otherwise it returns `false`. +在传统的编程中,逻辑或仅能够操作布尔值。如果参与运算的一个参数为 `true`,结果将返回 `true`,否则返回 `false`。 -In JavaScript the operator is a little bit more tricky and powerful. But first let's see what happens with boolean values. +在 JavaScript 中,逻辑运算符更加灵活强大。但是首先我们来看一下参与运算的布尔值发生了什么。 -There are four possible logical combinations: +下面是四种可能的逻辑组合: ```js run alert( true || true ); // true @@ -27,21 +27,21 @@ alert( true || false ); // true alert( false || false ); // false ``` -As we can see, the result is always `true` except for the case when both operands are `false`. +正如我们所见,除了两个操作数都是 `false` 的情况,结果总是 `true`。 -If an operand is not boolean, then it's converted to boolean for the evaluation. +如果操作数不是布尔值,那么它将会被转化为布尔值来参与运算。 -For instance, a number `1` is treated as `true`, a number `0` -- as `false`: +例如,数字 `1` 将会被作为 `true`,数字 `0` -- 则作为 `false`。 ```js run -if (1 || 0) { // works just like if( true || false ) +if (1 || 0) { // 工作原理相当于 if( true || false ) alert( 'truthy!' ); } ``` -Most of the time, OR `||` is used in an `if` statement to test if *any* of the given conditions is correct. +大多数时间,或 `||` 会被用在 `if` 语句中,来检测给定的条件是否正确。 -For example: +例如: ```js run let hour = 9; @@ -53,57 +53,57 @@ if (hour < 10 || hour > 18) { } ``` -We can pass more conditions: +我们可以浏览更多的情况: ```js run let hour = 12; let isWeekend = true; if (hour < 10 || hour > 18 || isWeekend) { - alert( 'The office is closed.' ); // it is the weekend + alert( 'The office is closed.' ); // 是周末 } ``` -## OR seeks the first truthy value +## 或运算寻找第一个有效值 -The logic described above is somewhat classical. Now let's bring in the "extra" features of JavaScript. +上文提到的逻辑处理多少有些传统了。下面让我们看看 JavaScript 的“附加”特性。 -The extended algorithm works as follows. +拓展计算如下所示。 -Given multiple OR'ed values: +给定多个参与或运算的值: ```js result = value1 || value2 || value3; ``` -The OR `||` operator does the following: +或运算符 `||` 做了如下的事情: -- Evaluate operands from left to right. -- For each operand, convert it to boolean. If the result is `true`, then stop and return the original value of that operand. -- If all other operands have been assessed (i.e. all were `false`), return the last operand. +- 从左到右依次计算操作数。 +- 将每一个操作数转化为布尔值。如果结果是 `true`,就停止计算,返回这个操作数的初始值。 +- 如果所有的操作数都被计算过(也就是,转换结果都是 `false`),返回最后一个操作数。 -A value is returned in its original form, without the conversion. +返回的值是操作数的初始形式,不会做布尔转换。 -In other words, a chain of OR `"||"` returns the first truthy value or the last one if no such value is found. +也就是,一个或 `"||"` 运算的链将返回第一个真(布尔转化后为 true 的,译者注)值,如果这样的值不存在就返回该链的最后一个值。 -For instance: +例如: ```js run -alert( 1 || 0 ); // 1 (1 is truthy) -alert( true || 'no matter what' ); // (true is truthy) +alert( 1 || 0 ); // 1(1 是真值) +alert( true || 'no matter what' ); //(true 是真值) -alert( null || 1 ); // 1 (1 is the first truthy value) -alert( null || 0 || 1 ); // 1 (the first truthy value) -alert( undefined || null || 0 ); // 0 (all falsy, returns the last value) +alert( null || 1 ); // 1(1 是第一个真值) +alert( null || 0 || 1 ); // 1(第一个真值) +alert( undefined || null || 0 ); // 0(所有的转化结果都是 false,返回最后一个值) ``` -That leads to some interesting usages compared to a "pure, classical, boolean-only OR". +对比与“纯粹的、传统的、仅仅处理布尔值的或运算”,这个就有很有趣的用法了。 -1. **Getting the first truthy value from the list of variables or expressions.** +1. **获取变量列表或者表达式的第一个真值** - Imagine we have several variables, which can either contain the data or be `null/undefined`. And we need to choose the first one with data. + 假设我们有几个变量,它们可能包含某些数据或者是 `null/undefined`。我们需要选出第一个包含数据的变量。 - We can use OR `||` for that: + 我们可以这样应用或运算 `||`: ```js run let currentUser = null; @@ -113,27 +113,27 @@ That leads to some interesting usages compared to a "pure, classical, boolean-on let name = currentUser || defaultUser || "unnamed"; */!* - alert( name ); // selects "John" – the first truthy value + alert( name ); // 选出了 “John” - 第一个真值 ``` - If both `currentUser` and `defaultUser` were falsy then `"unnamed"` would be the result. -2. **Short-circuit evaluation.** + 如果 `currentUser` 和 `defaultUser` 都是无效值,那么结果就是 `"unnamed"`。 +2. **短路取值。** - Operands can be not only values, but arbitrary expressions. OR evaluates and tests them from left to right. The evaluation stops when a truthy value is reached, and the value is returned. The process is called "a short-circuit evaluation", because it goes as short as possible from left to right. + 操作数不仅仅可能是值,还可能是任意表达式。或运算会从左到右计算并测试每个操作数。当找到第一个真值,计算就会停止,并返回这个值。这个过程就叫做“短路取值”,因为它将从左到右的计算尽可能的少。 - This is clearly seen when the expression given as the second argument has a side effect. Like a variable assignment. + 当表达式作为第二个参数并且有一定副作用 - 比如变量赋值 - 的时候,这就清楚可见了。 - If we run the example below, `x` would not get assigned: + 如果我们运行下面的例子,`x` 将不会被赋值: ```js run no-beautify let x; *!*true*/!* || (x = 1); - alert(x); // undefined, because (x = 1) not evaluated + alert(x); // undefined,因为 (x = 1) 没有被执行 ``` - ...And if the first argument is `false`, then `OR` goes on and evaluates the second one thus running the assignment: + ...如果第一个参数是 `false`,或运算将会继续并计算第二个参数,也就会运行赋值操作。 ```js run no-beautify let x; @@ -143,21 +143,21 @@ That leads to some interesting usages compared to a "pure, classical, boolean-on alert(x); // 1 ``` - An assignment is a simple case, other side effects can be involved. + 赋值操作只是一个很简单的情况,其他副作用同样可以被包含进来。 - As we can see, such a use case is a "shorter way to do `if`". The first operand is converted to boolean and if it's false then the second one is evaluated. + 正如我们所见,这种用法是“`if` 语句的简便方式”。第一个操作数被转化为布尔值,如果是假,那么第二个参数就会被执行。 - Most of time it's better to use a "regular" `if` to keep the code easy to understand, but sometimes that can be handy. + 大多数情况下,使用正常的 `if` 语句,这样代码可读性更高,但是有时候这种方式会很简洁。 -## && (AND) +## &&(与) -The AND operator is represented with two ampersands `&&`: +两个 & 符号表示 `&&` 与操作: ```js result = a && b; ``` -In classical programming AND returns `true` if both operands are truthy and `false` otherwise: +传统的编程中,当两个操作数都是真值,与操作返回 `true`,否则返回 `false`: ```js run alert( true && true ); // true @@ -166,7 +166,7 @@ alert( true && false ); // false alert( false && false ); // false ``` -An example with `if`: +使用 `if` 语句的例子: ```js run let hour = 12; @@ -177,72 +177,72 @@ if (hour == 12 && minute == 30) { } ``` -Just as for OR, any value is allowed as an operand of AND: +就像或运算一样,与运算的操作数可以是任意类型的值: ```js run -if (1 && 0) { // evaluated as true && false +if (1 && 0) { // 作为 true && false 来执行 alert( "won't work, because the result is falsy" ); } ``` -## AND seeks the first falsy value +## 与操作寻找第一个假值 -Given multiple AND'ed values: +给出多个参加与运算的值: ```js result = value1 && value2 && value3; ``` -The AND `&&` operator does the following: +与运算 `&&` 做了如下的事情: -- 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. +=- 从左到右依次计算操作数。 +- 将每一个操作数转化为布尔值。如果结果是 `false`,就停止计算,返回这个操作数的初始值。 +- 如果所有的操作数都被计算过(也就是,转换结果都是 `true`),返回最后一个操作数。 -In other words, AND returns the first falsy value or the last value if none were found. +换句话说,与操作符返回第一个假值,如果没有假值就返回最后一个值。(假值:将该变量进行布尔转换后为 `false`。译者注) -The rules above are similar to OR. The difference is that AND returns the first *falsy* value while OR returns the first *truthy* one. +上面的规则和或运算很像。区别就是与运算返回第一个假值而或操作返回第一个真值。 -Examples: +例如: ```js run -// if the first operand is truthy, -// AND returns the second operand: +// 如果第一个操作符是真值, +// 与操作返回第二个操作数: alert( 1 && 0 ); // 0 alert( 1 && 5 ); // 5 -// if the first operand is falsy, -// AND returns it. The second operand is ignored +// 如果第一个操作符是假值, +// 与操作直接返回它。第二个操作数被忽略 alert( null && 5 ); // null alert( 0 && "no matter what" ); // 0 ``` -We can also pass several values in a row. See how the first falsy one is returned: +我们也可以在一行代码上串联多个值。查看第一个假值是否被返回: ```js run alert( 1 && 2 && null && 3 ); // null ``` -When all values are truthy, the last value is returned: +如果所有的值都是真值,最后一个值将会被返回: ```js run -alert( 1 && 2 && 3 ); // 3, the last one +alert( 1 && 2 && 3 ); // 3,最后一个值 ``` -````smart header="AND `&&` executes before OR `||`" -The precedence of the AND `&&` operator is higher than OR `||`, so it executes before OR. +````聪明的头脑知道:"与运算 `&&` 在或操作符 `||` 之前执行" +与运算 `&&` 的优先级比或运算 `||` 要高,所以它将会比或运算先执行。 -In the code below `1 && 0` is calculated first: +下面代码中的,`1 && 0` 将会首先被运算: ```js run alert( 5 || 1 && 0 ); // 5 ``` ```` -Just like OR, the AND `&&` operator can sometimes replace `if`. +就像或运算一样,与运算 `&&` 有时候能够代替 `if`。 -For instance: +例如: ```js run let x = 1; @@ -250,9 +250,9 @@ let x = 1; (x > 0) && alert( 'Greater than zero!' ); ``` -The action in the right part of `&&` would execute only if the evaluation reaches it. That is: only if `(x > 0)` is true. +`&&` 右边的代码只有运算抵达到那里才能被执行。也就是,当且仅当 `(x > 0)` 返回了真值。 -So we basically have an analogue for: +所以我们基本可以类似的得到: ```js run let x = 1; @@ -262,42 +262,42 @@ if (x > 0) { } ``` -The variant with `&&` appears to be shorter. But `if` is more obvious and tends to be a little bit more readable. +带 `&&` 的代码变体看上去更短。但是 `if` 的含义更明显,可读性也更高。 -So it is recommended to use every construct for its purpose. Use `if` if we want if. And use `&&` if we want AND. +所以建议是根据目的选择代码的结构。需要条件判断就用 `if`,需要与运算就用 `&&`。 -## ! (NOT) +## !(非) -The boolean NOT operator is represented with an exclamation sign `!`. +感叹符号 `!` 表示布尔非运算。 -The syntax is pretty simple: +语法相当简单: ```js result = !value; ``` -The operator accepts a single argument and does the following: +操作符接受一个参数,并按如下运作: -1. Converts the operand to boolean type: `true/false`. -2. Returns an inverse value. +1. 将操作数转化为布尔类型:`true/false`。 +2. 返回相反的值。 -For instance: +例如: ```js run alert( !true ); // false alert( !0 ); // true ``` -A double NOT `!!` is sometimes used for converting a value to boolean type: +两个非运算 `!!` 有时候用来将某个值转化为布尔类型: ```js run alert( !!"non-empty string" ); // true alert( !!null ); // false ``` -That is, the first NOT converts the value to boolean and returns the inverse, and the second NOT inverses it again. At the end we have a plain value-to-boolean conversion. +也就是,第一个非运算将该值转化为布尔类型并取反,第二个非运算再次取反。最后我们就得到了一个任意值到布尔值的转化。 -There's a little more verbose way to do the same thing -- a built-in `Boolean` function: +这是一个更详细的方法,完成的同样的事情 -- 一个内置的 `Boolean` 函数: ```js run alert( Boolean("non-empty string") ); // true From ff5d85f81a8ce94e3c15d139aed26721ce47bf7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 12:52:02 +0800 Subject: [PATCH 02/41] Update task.md --- .../11-logical-operators/1-alert-null-2-undefined/task.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/task.md b/1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/task.md index eda8c90589..642fbe333c 100644 --- a/1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/task.md +++ b/1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/task.md @@ -1,10 +1,10 @@ -importance: 5 +重要性:5 --- -# What's the result of OR? +# 或运算的结果是什么? -What the code below is going to output? +如下代码将会输出什么? ```js alert( null || 2 || undefined ); From 1e53858b4c352e757cc8b1b00e1d8bd730d366a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 12:52:37 +0800 Subject: [PATCH 03/41] Update solution.md --- .../11-logical-operators/1-alert-null-2-undefined/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/solution.md b/1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/solution.md index 8869d32e6b..e4146accfc 100644 --- a/1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/solution.md +++ b/1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/solution.md @@ -1,4 +1,4 @@ -The answer is `2`, that's the first truthy value. +结果是 `2`,这是第一个真值。 ```js run alert( null || 2 || undefined ); From ba9c041cf9e64c7319ebedc6a443ddff5d2b5566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 13:25:04 +0800 Subject: [PATCH 04/41] Update solution.md --- .../11-logical-operators/2-alert-or/solution.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md b/1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md index 8f4d664e87..27f4d2d1cd 100644 --- a/1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md +++ b/1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md @@ -1,13 +1,13 @@ -The answer: first `1`, then `2`. +答案:第一个是 `1`,然后是 `2`。 ```js run alert( alert(1) || 2 || alert(3) ); ``` -The call to `alert` does not return a value. Or, in other words, it returns `undefined`. +对 `alert` 的调用没有返回值。或者说返回的是 `undefined`。 -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` 的信息。 +2. 函数 `alert` 返回了 `undefined`,所以或运算继续检查第二个参数,寻找真值。 +3. 第二个操作数 `2` 是真值,所以执行就中断了。`2` 被返回,并且被外层的 alert 显示。 -There will be no `3`, because the evaluation does not reach `alert(3)`. +不会显示 `3`,因为运算没有抵达到 `alert(3)`。 From 953d9f7493d972301347519ce7890807bea8320b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 13:25:36 +0800 Subject: [PATCH 05/41] Update solution.md --- 1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md b/1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md index 27f4d2d1cd..06a137ad95 100644 --- a/1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md +++ b/1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md @@ -10,4 +10,4 @@ alert( alert(1) || 2 || alert(3) ); 2. 函数 `alert` 返回了 `undefined`,所以或运算继续检查第二个参数,寻找真值。 3. 第二个操作数 `2` 是真值,所以执行就中断了。`2` 被返回,并且被外层的 alert 显示。 -不会显示 `3`,因为运算没有抵达到 `alert(3)`。 +不会显示 `3`,因为运算没有抵达 `alert(3)`。 From c02aad8bea1c68844682d778b25aca3c3175bacc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 13:27:09 +0800 Subject: [PATCH 06/41] Update task.md --- 1-js/02-first-steps/11-logical-operators/2-alert-or/task.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/02-first-steps/11-logical-operators/2-alert-or/task.md b/1-js/02-first-steps/11-logical-operators/2-alert-or/task.md index bc622abfc2..aae15d67a9 100644 --- a/1-js/02-first-steps/11-logical-operators/2-alert-or/task.md +++ b/1-js/02-first-steps/11-logical-operators/2-alert-or/task.md @@ -1,10 +1,10 @@ -importance: 3 +重要性:3 --- -# What's the result of OR'ed alerts? +# 或运算和 alerts 的结果是什么? -What the code below will output? +下面的代码将会输出什么? ```js alert( alert(1) || 2 || alert(3) ); From 58bb3c838f145200bbf144b0a25b47b16717b46e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 13:30:02 +0800 Subject: [PATCH 07/41] Update task.md --- .../11-logical-operators/3-alert-1-null-2/task.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md b/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md index 53ec7874ac..d4e1ca4a5d 100644 --- a/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md +++ b/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md @@ -1,10 +1,10 @@ -importance: 5 +重要性:5 --- -# What is the result of AND? +# 与操作的结果是什么? -What this code is going to show? +下面这段代码将会显示什么? ```js alert( 1 && null && 2 ); From f7fcbc3a1c0c19eccc142be441522f7370a55cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 13:30:47 +0800 Subject: [PATCH 08/41] Update task.md --- .../11-logical-operators/3-alert-1-null-2/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md b/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md index d4e1ca4a5d..5b4f855601 100644 --- a/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md +++ b/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md @@ -4,7 +4,7 @@ # 与操作的结果是什么? -下面这段代码将会显示什么? +下面这段代码将会输出什么? ```js alert( 1 && null && 2 ); From 759ef6fd8d4b11b6d34a9a40df11f1d3f933284b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 13:31:35 +0800 Subject: [PATCH 09/41] Update solution.md --- .../11-logical-operators/3-alert-1-null-2/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/solution.md b/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/solution.md index 5c2455ef48..4ed9b855b9 100644 --- a/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/solution.md +++ b/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/solution.md @@ -1,4 +1,4 @@ -The answer: `null`, because it's the first falsy value from the list. +答案:`null`,因为它是列表中第一个假值。 ```js run alert( 1 && null && 2 ); From a124e269ae07015ec7c852ed926d9a14537ce69c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 13:32:30 +0800 Subject: [PATCH 10/41] Update task.md --- .../11-logical-operators/3-alert-1-null-2/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md b/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md index 5b4f855601..d4e1ca4a5d 100644 --- a/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md +++ b/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md @@ -4,7 +4,7 @@ # 与操作的结果是什么? -下面这段代码将会输出什么? +下面这段代码将会显示什么? ```js alert( 1 && null && 2 ); From 6e7042213c851ae28042f4b6114b503b52b77705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 13:33:47 +0800 Subject: [PATCH 11/41] Update task.md --- .../02-first-steps/11-logical-operators/4-alert-and/task.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/02-first-steps/11-logical-operators/4-alert-and/task.md b/1-js/02-first-steps/11-logical-operators/4-alert-and/task.md index 69f877b955..b41be945fc 100644 --- a/1-js/02-first-steps/11-logical-operators/4-alert-and/task.md +++ b/1-js/02-first-steps/11-logical-operators/4-alert-and/task.md @@ -1,10 +1,10 @@ -importance: 3 +重要性:3 --- -# What is the result of AND'ed alerts? +# 与操作和 alerts 的结果是什么? -What will this code show? +这段代码将会显示什么? ```js alert( alert(1) && alert(2) ); From 2b064fcb83c253326fa5073aa9fa484332ee90c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 13:34:21 +0800 Subject: [PATCH 12/41] Update task.md --- 1-js/02-first-steps/11-logical-operators/4-alert-and/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/4-alert-and/task.md b/1-js/02-first-steps/11-logical-operators/4-alert-and/task.md index b41be945fc..750491dbb4 100644 --- a/1-js/02-first-steps/11-logical-operators/4-alert-and/task.md +++ b/1-js/02-first-steps/11-logical-operators/4-alert-and/task.md @@ -2,7 +2,7 @@ --- -# 与操作和 alerts 的结果是什么? +# 与运算和 alerts 的结果是什么? 这段代码将会显示什么? From 5ff4fbff4c1d68abc9c2a7d10fd3818a758fc027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 13:38:56 +0800 Subject: [PATCH 13/41] Update solution.md --- .../11-logical-operators/4-alert-and/solution.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/02-first-steps/11-logical-operators/4-alert-and/solution.md b/1-js/02-first-steps/11-logical-operators/4-alert-and/solution.md index b6fb10d720..46c61033d6 100644 --- a/1-js/02-first-steps/11-logical-operators/4-alert-and/solution.md +++ b/1-js/02-first-steps/11-logical-operators/4-alert-and/solution.md @@ -1,10 +1,10 @@ -The answer: `1`, and then `undefined`. +答案:`1`,然后 `undefined`。 ```js run alert( alert(1) && alert(2) ); ``` -The call to `alert` returns `undefined` (it just shows a message, so there's no meaningful return). +调用 `alert` 返回了 `undefined`(它只展示消息,所以没有有意义的返回值)。 -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` 是一个假值。并且 `&&` 就是寻找假值然后返回它,所以运算结束。 From 7bd38b05bb60280e3ddd10679eaad84ae50043fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 13:40:41 +0800 Subject: [PATCH 14/41] Update task.md --- .../11-logical-operators/5-alert-and-or/task.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/02-first-steps/11-logical-operators/5-alert-and-or/task.md b/1-js/02-first-steps/11-logical-operators/5-alert-and-or/task.md index 4b2ad046e5..2549a36587 100644 --- a/1-js/02-first-steps/11-logical-operators/5-alert-and-or/task.md +++ b/1-js/02-first-steps/11-logical-operators/5-alert-and-or/task.md @@ -1,10 +1,10 @@ -importance: 5 +重要性:5 --- -# The result of OR AND OR +# 或操作、与操作、或操作串联的结果 -What will be the result? +结果将会是什么? ```js alert( null || 2 && 3 || 4 ); From 8b7dd234280d08e84ee93f6529a8337c153458f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 13:41:03 +0800 Subject: [PATCH 15/41] Update task.md --- 1-js/02-first-steps/11-logical-operators/5-alert-and-or/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/5-alert-and-or/task.md b/1-js/02-first-steps/11-logical-operators/5-alert-and-or/task.md index 2549a36587..b381171836 100644 --- a/1-js/02-first-steps/11-logical-operators/5-alert-and-or/task.md +++ b/1-js/02-first-steps/11-logical-operators/5-alert-and-or/task.md @@ -2,7 +2,7 @@ --- -# 或操作、与操作、或操作串联的结果 +# 或运算、与运算、或运算串联的结果 结果将会是什么? From 26e8909d31f4f2e935e47e83dc52f127f1801048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 13:45:41 +0800 Subject: [PATCH 16/41] Update solution.md --- .../11-logical-operators/5-alert-and-or/solution.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/1-js/02-first-steps/11-logical-operators/5-alert-and-or/solution.md b/1-js/02-first-steps/11-logical-operators/5-alert-and-or/solution.md index 32a8ccf257..b61e034948 100644 --- a/1-js/02-first-steps/11-logical-operators/5-alert-and-or/solution.md +++ b/1-js/02-first-steps/11-logical-operators/5-alert-and-or/solution.md @@ -1,16 +1,16 @@ -The answer: `3`. +答案:`3`。 ```js run alert( null || 2 && 3 || 4 ); ``` -The precedence of AND `&&` is higher than `||`, so it executes first. +与运算 `&&` 的优先级比 `||` 高,所以它第一个被执行。 -The result of `2 && 3 = 3`, so the expression becomes: +结果是 `2 && 3 = 3`,所以表达式变成了: ``` null || 3 || 4 ``` -Now the result if the first truthy value: `3`. +现在结果是第一个真值: `3`。 From 87511ead2dcdac4bcbc30a809d57868ee7223de8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 13:45:52 +0800 Subject: [PATCH 17/41] Update solution.md --- .../11-logical-operators/5-alert-and-or/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/5-alert-and-or/solution.md b/1-js/02-first-steps/11-logical-operators/5-alert-and-or/solution.md index b61e034948..9e9d6053dc 100644 --- a/1-js/02-first-steps/11-logical-operators/5-alert-and-or/solution.md +++ b/1-js/02-first-steps/11-logical-operators/5-alert-and-or/solution.md @@ -12,5 +12,5 @@ alert( null || 2 && 3 || 4 ); null || 3 || 4 ``` -现在结果是第一个真值: `3`。 +现在的结果就是第一个真值: `3`。 From 969afac8d11d6e70024768bea084cf6460f11b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 14:11:32 +0800 Subject: [PATCH 18/41] Update task.md --- .../11-logical-operators/6-check-if-in-range/task.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/1-js/02-first-steps/11-logical-operators/6-check-if-in-range/task.md b/1-js/02-first-steps/11-logical-operators/6-check-if-in-range/task.md index cc00ca9fcd..861e0ee520 100644 --- a/1-js/02-first-steps/11-logical-operators/6-check-if-in-range/task.md +++ b/1-js/02-first-steps/11-logical-operators/6-check-if-in-range/task.md @@ -1,9 +1,9 @@ -importance: 3 +重要性:3 --- -# Check the range between +# 检查范围区间 -Write an "if" condition to check that `age` is between `14` and `90` inclusively. +写一个“if”条件句来检查 `age` 是否位于 `14` 到 `90` 的闭区间。 -"Inclusively" means that `age` can reach the edges `14` or `90`. +“闭区间”意味着,`age` 的值可以取 `14` 或 `90`。 From f1628cbaa5b3d0e0d83c39c667ad1c9a090bcdc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 14:14:05 +0800 Subject: [PATCH 19/41] Update task.md --- .../11-logical-operators/7-check-if-out-range/task.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/task.md b/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/task.md index 7c22d6ad1d..70c815dea1 100644 --- a/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/task.md +++ b/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/task.md @@ -1,9 +1,9 @@ -importance: 3 +重要性:3 --- -# Check the range outside +# 检测值是否位于范围之外 -Write an `if` condition to check that `age` is NOT between 14 and 90 inclusively. +写一个 `if` 条件句,检查 `age` 是否不位于 14 到 90 的闭区间。 -Create two variants: the first one using NOT `!`, the second one -- without it. +创建两个变量:第一个用非运算 `!`,第二个不用。 From 51bc64db2eae010e8f6d6ce25b33823a8ee1a22c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 14:14:34 +0800 Subject: [PATCH 20/41] Update task.md --- .../11-logical-operators/6-check-if-in-range/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/6-check-if-in-range/task.md b/1-js/02-first-steps/11-logical-operators/6-check-if-in-range/task.md index 861e0ee520..e9f49163da 100644 --- a/1-js/02-first-steps/11-logical-operators/6-check-if-in-range/task.md +++ b/1-js/02-first-steps/11-logical-operators/6-check-if-in-range/task.md @@ -2,7 +2,7 @@ --- -# 检查范围区间 +# 检查值是否位于范围区间内 写一个“if”条件句来检查 `age` 是否位于 `14` 到 `90` 的闭区间。 From e1c3824b25e19b35c4338fd2f75f8745ac8b8000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 14:16:12 +0800 Subject: [PATCH 21/41] Update task.md --- .../11-logical-operators/7-check-if-out-range/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/task.md b/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/task.md index 70c815dea1..394e071abf 100644 --- a/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/task.md +++ b/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/task.md @@ -6,4 +6,4 @@ 写一个 `if` 条件句,检查 `age` 是否不位于 14 到 90 的闭区间。 -创建两个变量:第一个用非运算 `!`,第二个不用。 +创建两个表达式:第一个用非运算 `!`,第二个不用。 From 6a30d263c5112c71de9340f75636edc1be73387b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 14:16:40 +0800 Subject: [PATCH 22/41] Update solution.md --- .../11-logical-operators/7-check-if-out-range/solution.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/solution.md b/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/solution.md index d1946a9673..dffe0b3e17 100644 --- a/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/solution.md +++ b/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/solution.md @@ -1,10 +1,10 @@ -The first variant: +第一个表达式: ```js if (!(age >= 14 && age <= 90)) ``` -The second variant: +第二个表达式: ```js if (age < 14 || age > 90) From dce6511900280241e181cdfb9c440b4a0ac33fe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 14:21:41 +0800 Subject: [PATCH 23/41] Update task.md --- .../11-logical-operators/8-if-question/task.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/1-js/02-first-steps/11-logical-operators/8-if-question/task.md b/1-js/02-first-steps/11-logical-operators/8-if-question/task.md index f824779bf6..6857f19a8c 100644 --- a/1-js/02-first-steps/11-logical-operators/8-if-question/task.md +++ b/1-js/02-first-steps/11-logical-operators/8-if-question/task.md @@ -1,12 +1,12 @@ -importance: 5 +重要性:5 --- -# A question about "if" +# 一个关于“if”的问题 -Which of these `alert`s are going to execute? +下面哪一个 `alert` 将会被执行? -What will be the results of the expressions inside `if(...)`? +`if(...)` 语句内表达式的结果是什么? ```js if (-1 || 0) alert( 'first' ); From 30c67a84cacdac5d6a6b8c7325da6ed0b6950bab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Mon, 23 Apr 2018 14:27:52 +0800 Subject: [PATCH 24/41] Update solution.md --- .../8-if-question/solution.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/1-js/02-first-steps/11-logical-operators/8-if-question/solution.md b/1-js/02-first-steps/11-logical-operators/8-if-question/solution.md index 2105097584..753589cca8 100644 --- a/1-js/02-first-steps/11-logical-operators/8-if-question/solution.md +++ b/1-js/02-first-steps/11-logical-operators/8-if-question/solution.md @@ -1,19 +1,19 @@ -The answer: the first and the third will execute. +答案:第一个和第三个将会被执行。 -Details: +详解: ```js run -// Runs. -// The result of -1 || 0 = -1, truthy +// 执行。 +// -1 || 0 的结果为 -1,真值 if (-1 || 0) alert( 'first' ); -// Doesn't run -// -1 && 0 = 0, falsy +// 不执行。 +// -1 && 0 = 0, 假值 if (-1 && 0) alert( 'second' ); -// Executes -// Operator && has a higher precedence than || -// so -1 && 1 executes first, giving us the chain: +// 执行 +// && 运算的优先级比 || 高 +// 所以 -1 && 1 先执行,给出如下运算链: // null || -1 && 1 -> null || 1 -> 1 if (null || -1 && 1) alert( 'third' ); ``` From d04ee4ec6708228261a191e9a721acb94b70ea07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Tue, 24 Apr 2018 07:26:21 +0800 Subject: [PATCH 25/41] Update solution.md --- .../11-logical-operators/2-alert-or/solution.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md b/1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md index 06a137ad95..5bacd774d4 100644 --- a/1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md +++ b/1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md @@ -1,4 +1,4 @@ -答案:第一个是 `1`,然后是 `2`。 +答案:首先是 `1`,然后是 `2`。 ```js run alert( alert(1) || 2 || alert(3) ); @@ -6,8 +6,8 @@ alert( alert(1) || 2 || alert(3) ); 对 `alert` 的调用没有返回值。或者说返回的是 `undefined`。 -1. 第一个或运算 `||` 对它左边的 `alert(1)` 进行了计算。这就显示了第一条 `1` 的信息。 -2. 函数 `alert` 返回了 `undefined`,所以或运算继续检查第二个参数,寻找真值。 +1. 第一个或运算 `||` 对它的左值 `alert(1)` 进行了计算。这就显示了第一条 `1` 的信息。 +2. 函数 `alert` 返回了 `undefined`,所以或运算继续检查第二个操作数,寻找真值。 3. 第二个操作数 `2` 是真值,所以执行就中断了。`2` 被返回,并且被外层的 alert 显示。 不会显示 `3`,因为运算没有抵达 `alert(3)`。 From b33b01909880d1d90d396b82ad0faeb16ed07397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Tue, 24 Apr 2018 07:27:37 +0800 Subject: [PATCH 26/41] Update task.md --- 1-js/02-first-steps/11-logical-operators/4-alert-and/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/4-alert-and/task.md b/1-js/02-first-steps/11-logical-operators/4-alert-and/task.md index 750491dbb4..7422b39500 100644 --- a/1-js/02-first-steps/11-logical-operators/4-alert-and/task.md +++ b/1-js/02-first-steps/11-logical-operators/4-alert-and/task.md @@ -2,7 +2,7 @@ --- -# 与运算和 alerts 的结果是什么? +# 与运算连接的 alerts 的结果是什么? 这段代码将会显示什么? From c656e5d07b14df7911c4222a1546f30a344d9dd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Tue, 24 Apr 2018 07:32:19 +0800 Subject: [PATCH 27/41] Update article.md --- .../11-logical-operators/article.md | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/1-js/02-first-steps/11-logical-operators/article.md b/1-js/02-first-steps/11-logical-operators/article.md index 56db2ea893..41ca559a22 100644 --- a/1-js/02-first-steps/11-logical-operators/article.md +++ b/1-js/02-first-steps/11-logical-operators/article.md @@ -16,7 +16,7 @@ result = a || b; 在传统的编程中,逻辑或仅能够操作布尔值。如果参与运算的一个参数为 `true`,结果将返回 `true`,否则返回 `false`。 -在 JavaScript 中,逻辑运算符更加灵活强大。但是首先我们来看一下参与运算的布尔值发生了什么。 +在 JavaScript 中,逻辑运算符更加灵活强大。但是首先我们看一下操作数是布尔值的时候发生了什么。 下面是四种可能的逻辑组合: @@ -39,7 +39,7 @@ if (1 || 0) { // 工作原理相当于 if( true || false ) } ``` -大多数时间,或 `||` 会被用在 `if` 语句中,来检测给定的条件是否正确。 +大多数时间,或 `||` 会被用在 `if` 语句中,用来测试是否有**任何**给定的条件是正确的。 例如: @@ -53,7 +53,7 @@ if (hour < 10 || hour > 18) { } ``` -我们可以浏览更多的情况: +我们可以传入更多的条件: ```js run let hour = 12; @@ -64,11 +64,11 @@ if (hour < 10 || hour > 18 || isWeekend) { } ``` -## 或运算寻找第一个有效值 +## 或运算寻找第一个真值 上文提到的逻辑处理多少有些传统了。下面让我们看看 JavaScript 的“附加”特性。 -拓展计算如下所示。 +拓展的算法如下所示。 给定多个参与或运算的值: @@ -84,7 +84,7 @@ result = value1 || value2 || value3; 返回的值是操作数的初始形式,不会做布尔转换。 -也就是,一个或 `"||"` 运算的链将返回第一个真(布尔转化后为 true 的,译者注)值,如果这样的值不存在就返回该链的最后一个值。 +也就是,一个或 `"||"` 运算的链将返回第一个真值,如果这样的值不存在就返回该链的最后一个值。 例如: @@ -116,12 +116,12 @@ alert( undefined || null || 0 ); // 0(所有的转化结果都是 false,返 alert( name ); // 选出了 “John” - 第一个真值 ``` - 如果 `currentUser` 和 `defaultUser` 都是无效值,那么结果就是 `"unnamed"`。 +    如果 `currentUser` 和 `defaultUser` 都是假值,那么结果就是 `"unnamed"`。 2. **短路取值。** 操作数不仅仅可能是值,还可能是任意表达式。或运算会从左到右计算并测试每个操作数。当找到第一个真值,计算就会停止,并返回这个值。这个过程就叫做“短路取值”,因为它将从左到右的计算尽可能的少。 - 当表达式作为第二个参数并且有一定副作用 - 比如变量赋值 - 的时候,这就清楚可见了。 +    当表达式作为第二个参数并且有一定副作用,比如变量赋值,的时候,这就清楚可见了。 如果我们运行下面的例子,`x` 将不会被赋值: @@ -151,7 +151,7 @@ alert( undefined || null || 0 ); // 0(所有的转化结果都是 false,返 ## &&(与) -两个 & 符号表示 `&&` 与操作: +两个 & 符号表示 `&&` 与操作: ```js result = a && b; @@ -196,11 +196,11 @@ result = value1 && value2 && value3; 与运算 `&&` 做了如下的事情: -=- 从左到右依次计算操作数。 +- 从左到右依次计算操作数。 - 将每一个操作数转化为布尔值。如果结果是 `false`,就停止计算,返回这个操作数的初始值。 - 如果所有的操作数都被计算过(也就是,转换结果都是 `true`),返回最后一个操作数。 -换句话说,与操作符返回第一个假值,如果没有假值就返回最后一个值。(假值:将该变量进行布尔转换后为 `false`。译者注) +换句话说,与操作符返回第一个假值,如果没有假值就返回最后一个值。 上面的规则和或运算很像。区别就是与运算返回第一个假值而或操作返回第一个真值。 From e0a0a3e887c5375b94ccb6c55b3671bd6a835290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Tue, 24 Apr 2018 07:33:16 +0800 Subject: [PATCH 28/41] Update task.md --- .../11-logical-operators/1-alert-null-2-undefined/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/task.md b/1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/task.md index 642fbe333c..512fd6f33a 100644 --- a/1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/task.md +++ b/1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/task.md @@ -1,4 +1,4 @@ -重要性:5 +importance: 5 --- From d4cd39691779cbf065bcee72ee9c9323f16c52c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Tue, 24 Apr 2018 07:33:40 +0800 Subject: [PATCH 29/41] Update task.md --- 1-js/02-first-steps/11-logical-operators/2-alert-or/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/2-alert-or/task.md b/1-js/02-first-steps/11-logical-operators/2-alert-or/task.md index aae15d67a9..fac364cc24 100644 --- a/1-js/02-first-steps/11-logical-operators/2-alert-or/task.md +++ b/1-js/02-first-steps/11-logical-operators/2-alert-or/task.md @@ -1,4 +1,4 @@ -重要性:3 +importance: 3 --- From 688b198f53d70bd7c1fb5e0cd47a5b279a8a658d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Tue, 24 Apr 2018 07:34:02 +0800 Subject: [PATCH 30/41] Update task.md --- .../11-logical-operators/3-alert-1-null-2/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md b/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md index d4e1ca4a5d..2331e3e223 100644 --- a/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md +++ b/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md @@ -1,4 +1,4 @@ -重要性:5 +importance: 5 --- From 1826831e8cc73f491d5bdf04a3487874f2a2b38f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Tue, 24 Apr 2018 07:34:26 +0800 Subject: [PATCH 31/41] Update task.md --- 1-js/02-first-steps/11-logical-operators/4-alert-and/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/4-alert-and/task.md b/1-js/02-first-steps/11-logical-operators/4-alert-and/task.md index 7422b39500..ac5717cc6e 100644 --- a/1-js/02-first-steps/11-logical-operators/4-alert-and/task.md +++ b/1-js/02-first-steps/11-logical-operators/4-alert-and/task.md @@ -1,4 +1,4 @@ -重要性:3 +importance: 3 --- From d1b13f50005830df877802d093ab1d60b1f47501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Tue, 24 Apr 2018 07:34:47 +0800 Subject: [PATCH 32/41] Update task.md --- 1-js/02-first-steps/11-logical-operators/5-alert-and-or/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/5-alert-and-or/task.md b/1-js/02-first-steps/11-logical-operators/5-alert-and-or/task.md index b381171836..05b7f18aa7 100644 --- a/1-js/02-first-steps/11-logical-operators/5-alert-and-or/task.md +++ b/1-js/02-first-steps/11-logical-operators/5-alert-and-or/task.md @@ -1,4 +1,4 @@ -重要性:5 +importance: 5 --- From 95adb85f54992a23578b4f2f9f331f721ced5cc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Tue, 24 Apr 2018 07:35:03 +0800 Subject: [PATCH 33/41] Update task.md --- .../11-logical-operators/6-check-if-in-range/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/6-check-if-in-range/task.md b/1-js/02-first-steps/11-logical-operators/6-check-if-in-range/task.md index e9f49163da..c7719cd203 100644 --- a/1-js/02-first-steps/11-logical-operators/6-check-if-in-range/task.md +++ b/1-js/02-first-steps/11-logical-operators/6-check-if-in-range/task.md @@ -1,4 +1,4 @@ -重要性:3 +importance: 3 --- From 00b7deb8ce85ecf9b68c95114b5bbd55bd5b710e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Tue, 24 Apr 2018 07:35:19 +0800 Subject: [PATCH 34/41] Update task.md --- .../11-logical-operators/7-check-if-out-range/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/task.md b/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/task.md index 394e071abf..8a36a624d8 100644 --- a/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/task.md +++ b/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/task.md @@ -1,4 +1,4 @@ -重要性:3 +importance: 3 --- From 80229cb8d61b564d6513b4acfe319a2b15f92d49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Tue, 24 Apr 2018 07:35:35 +0800 Subject: [PATCH 35/41] Update task.md --- 1-js/02-first-steps/11-logical-operators/8-if-question/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/8-if-question/task.md b/1-js/02-first-steps/11-logical-operators/8-if-question/task.md index 6857f19a8c..0947acd529 100644 --- a/1-js/02-first-steps/11-logical-operators/8-if-question/task.md +++ b/1-js/02-first-steps/11-logical-operators/8-if-question/task.md @@ -1,4 +1,4 @@ -重要性:5 +importance: 3 --- From 3debe14c1e03810082415fa98963a3dc65a4f643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Tue, 24 Apr 2018 07:35:44 +0800 Subject: [PATCH 36/41] Update task.md --- 1-js/02-first-steps/11-logical-operators/8-if-question/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/8-if-question/task.md b/1-js/02-first-steps/11-logical-operators/8-if-question/task.md index 0947acd529..322fdc5f19 100644 --- a/1-js/02-first-steps/11-logical-operators/8-if-question/task.md +++ b/1-js/02-first-steps/11-logical-operators/8-if-question/task.md @@ -1,4 +1,4 @@ -importance: 3 +importance: 5 --- From f0636a97405d2ec77cb6cbbb178be603f939717f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Tue, 24 Apr 2018 07:37:13 +0800 Subject: [PATCH 37/41] Update solution.md --- .../02-first-steps/11-logical-operators/4-alert-and/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/4-alert-and/solution.md b/1-js/02-first-steps/11-logical-operators/4-alert-and/solution.md index 46c61033d6..e7536e461c 100644 --- a/1-js/02-first-steps/11-logical-operators/4-alert-and/solution.md +++ b/1-js/02-first-steps/11-logical-operators/4-alert-and/solution.md @@ -6,5 +6,5 @@ alert( alert(1) && alert(2) ); 调用 `alert` 返回了 `undefined`(它只展示消息,所以没有有意义的返回值)。 -因此,`&&` 计算了它左边的操作数(显示 `1`),然后立即停止了,因为 `undefined` 是一个假值。并且 `&&` 就是寻找假值然后返回它,所以运算结束。 +因此,`&&` 计算了它左边的操作数(显示 `1`),然后立即停止了,因为 `undefined` 是一个假值。并且 `&&` 就是寻找假值然后返回它,所以运算结束。 From 1922597b08316961bdc9138a1149b418d3411d99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Tue, 24 Apr 2018 07:38:40 +0800 Subject: [PATCH 38/41] Update solution.md --- .../11-logical-operators/8-if-question/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/8-if-question/solution.md b/1-js/02-first-steps/11-logical-operators/8-if-question/solution.md index 753589cca8..fb533026b3 100644 --- a/1-js/02-first-steps/11-logical-operators/8-if-question/solution.md +++ b/1-js/02-first-steps/11-logical-operators/8-if-question/solution.md @@ -8,7 +8,7 @@ if (-1 || 0) alert( 'first' ); // 不执行。 -// -1 && 0 = 0, 假值 +// -1 && 0 = 0,假值 if (-1 && 0) alert( 'second' ); // 执行 From cbfca762e00d1c4f414e2efddec2fb52c305c744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=84=BF?= Date: Tue, 24 Apr 2018 07:39:29 +0800 Subject: [PATCH 39/41] Update task.md --- 1-js/02-first-steps/11-logical-operators/8-if-question/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/8-if-question/task.md b/1-js/02-first-steps/11-logical-operators/8-if-question/task.md index 322fdc5f19..466673e2a9 100644 --- a/1-js/02-first-steps/11-logical-operators/8-if-question/task.md +++ b/1-js/02-first-steps/11-logical-operators/8-if-question/task.md @@ -2,7 +2,7 @@ importance: 5 --- -# 一个关于“if”的问题 +# 一个关于 "if" 的问题 下面哪一个 `alert` 将会被执行? From c91b18e527d01853ec0394a14a76cf227a4e451b Mon Sep 17 00:00:00 2001 From: LeviDing Date: Tue, 24 Apr 2018 07:42:43 +0800 Subject: [PATCH 40/41] Update solution.md --- .../11-logical-operators/5-alert-and-or/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/5-alert-and-or/solution.md b/1-js/02-first-steps/11-logical-operators/5-alert-and-or/solution.md index 9e9d6053dc..c98fae47c1 100644 --- a/1-js/02-first-steps/11-logical-operators/5-alert-and-or/solution.md +++ b/1-js/02-first-steps/11-logical-operators/5-alert-and-or/solution.md @@ -12,5 +12,5 @@ alert( null || 2 && 3 || 4 ); null || 3 || 4 ``` -现在的结果就是第一个真值: `3`。 +现在的结果就是第一个真值:`3`。 From b6a0f2ada1fb1780cdfc7f1e98fd70bdf4fe500e Mon Sep 17 00:00:00 2001 From: LeviDing Date: Tue, 24 Apr 2018 07:45:18 +0800 Subject: [PATCH 41/41] Update article.md --- 1-js/02-first-steps/11-logical-operators/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/11-logical-operators/article.md b/1-js/02-first-steps/11-logical-operators/article.md index 41ca559a22..e7d370c979 100644 --- a/1-js/02-first-steps/11-logical-operators/article.md +++ b/1-js/02-first-steps/11-logical-operators/article.md @@ -31,7 +31,7 @@ alert( false || false ); // false 如果操作数不是布尔值,那么它将会被转化为布尔值来参与运算。 -例如,数字 `1` 将会被作为 `true`,数字 `0` -- 则作为 `false`。 +例如,数字 `1` 将会被作为 `true`,数字 `0` 则作为 `false`: ```js run if (1 || 0) { // 工作原理相当于 if( true || false )