Skip to content

Commit 337a155

Browse files
committed
logical tasks
1 parent 6a9d746 commit 337a155

8 files changed

Lines changed: 20 additions & 18 deletions

File tree

1-js/2-first-steps/13-logical-ops/1-alert-null-2-undefined/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Ответ: `2`, это первое значение, которое в логическом контексте даст `true`.
1+
The answer is `2`, that's the first truthy value.
22

33
```js
44
//+ run

1-js/2-first-steps/13-logical-ops/1-alert-null-2-undefined/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Что выведет alert (ИЛИ)?
1+
# What's the result of OR?
22

33
[importance 5]
44

5-
Что выведет код ниже?
5+
What the code below is going to output?
66

77
```js
88
alert( null || 2 || undefined );
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
Ответ: сначала `1`, затем `2`.
1+
The answer: first `1`, then `2`.
22

33
```js
44
//+ run
55
alert( alert(1) || 2 || alert(3) );
66
```
77

8-
Вызов `alert` не возвращает значения, или, иначе говоря, возвращает `undefined`.
8+
The call to `alert` does not return a value. Or, in other words, it returns `undefined`.
99

1010
<ol>
11-
<li>Первый оператор ИЛИ `||` выполнит первый `alert(1)`, получит `undefined` и пойдёт дальше, ко второму операнду.</li>
12-
<li>Так как второй операнд `2` является истинным, то вычисления завершатся, результатом `undefined || 2` будет `2`, которое будет выведено внешним `alert( .... )`.</li>
11+
<li>The first OR `||` evaluates it's left operand `alert(1)`. That shows the first message with `1`.</li>
12+
<li>The `alert` returns `undefined`, so OR goes on to the second operand in it's search of a truthy value.</li>
13+
<li>The second operand `2` is truthy, so the execution is halted, `2` is returned and then shown by the outer alert.</li>
1314
</ol>
1415

15-
Второй оператор `||` не будет выполнен, выполнение до `alert(3)` не дойдёт, поэтому `3` выведено не будет.
16+
There will be no `3`, because the evaluation does not reach `alert(3)`.

1-js/2-first-steps/13-logical-ops/2-alert-or/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Что выведет alert (ИЛИ)?
1+
# What's the result of OR'ed alerts?
22

33
[importance 3]
44

5-
Что выведет код ниже?
5+
What the code below will output?
66

77
```js
88
alert( alert(1) || 2 || alert(3) );

1-js/2-first-steps/13-logical-ops/3-alert-1-null-2/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Ответ: `null`, это первое ложное значение из списка.
1+
The answer: `null`, because it's the first falsy value from the list.
22

33
```js
44
//+ run

1-js/2-first-steps/13-logical-ops/3-alert-1-null-2/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Что выведет alert (И)?
1+
# What is the result of AND?
22

33
[importance 5]
44

5-
Что выведет код ниже?
5+
What this code is going to show?
66

77
```js
88
alert( 1 && null && 2 );

1-js/2-first-steps/13-logical-ops/4-alert-and/solution.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
Ответ: `1`, а затем `undefined`.
1+
The answer: `1`, and then `undefined`.
22

33
```js
44
//+ run
55
alert( alert(1) && alert(2) );
66
```
7+
8+
The call to `alert` does not return a value or, in other words, returns `undefined`.
79

8-
Вызов `alert` не возвращает значения, или, иначе говоря, возвращает `undefined`.
10+
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.
911

10-
Поэтому до правого `alert` дело не дойдёт, вычисления закончатся на левом.

1-js/2-first-steps/13-logical-ops/4-alert-and/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Что выведет alert (И)?
1+
# What is the result of AND'ed alerts?
22

33
[importance 3]
44

5-
Что выведет код ниже?
5+
What will this code show?
66

77
```js
88
alert( alert(1) && alert(2) );

0 commit comments

Comments
 (0)