File tree Expand file tree Collapse file tree 7 files changed +36
-35
lines changed
1-js/2-first-steps/13-logical-ops Expand file tree Collapse file tree 7 files changed +36
-35
lines changed Original file line number Diff line number Diff line change 1- Ответ : ` 3 ` .
1+ The answer : ` 3 ` .
22
33``` js
44// + run
55alert ( null || 2 && 3 || 4 );
66```
77
8- Приоритет оператора ` && ` выше, чем ` || ` , поэтому он выполнится первым.
8+ The precedence of AND ` && ` is higher than ` || ` , so it executes first.
9+
10+ The result of ` 2 && 3 = 3 ` , so the expression becomes:
911
10- Последовательность вычислений:
1112```
12- null || 2 && 3 || 4
13- null || 3 || 4
14- 3
13+ null || 3 || 4
1514```
1615
16+ Now the result if the first truthy value: ` 3 ` .
17+
Original file line number Diff line number Diff line change 1- # Что выведет этот код?
1+ # The result of OR AND OR
22
33[ importance 5]
44
5- Что выведет код ниже ?
5+ What will be the result ?
66
77``` js
88alert ( null || 2 && 3 || 4 );
Original file line number Diff line number Diff line change 1- # Проверка if внутри диапазона
1+ # Check the range between
22
33[ importance 3]
44
5- Напишите условие ` if ` для проверки того факта, что переменная ` age ` находится между ` 14 ` и ` 90 ` включительно .
5+ Write an "if" condition to check that ` age ` is between ` 14 ` and ` 90 ` inclusively .
66
7- "Включительно" означает, что концы промежутка включены, то есть ` age ` может быть равна ` 14 ` или ` 90 ` .
7+ "Inclusively" means that ` age ` can reach the edges ` 14 ` or ` 90 ` .
Original file line number Diff line number Diff line change 1- Первый вариант :
1+ The first variant :
22
33``` js
44if (! (age >= 14 && age <= 90 ))
55```
66
7- Второй вариант :
7+ The second variant :
88
99``` js
1010if (age < 14 || age > 90 )
Original file line number Diff line number Diff line change 1- # Проверка if вне диапазона
1+ # Check the range outside
22
33[ importance 3]
44
5- Напишите условие ` if ` для проверки того факта, что ` age ` НЕ находится между 14 и 90 включительно .
5+ Write an ` if ` condition to check that ` age ` is NOT between 14 and 90 inclusively .
66
7- Сделайте два варианта условия: первый с использованием оператора НЕ ` ! ` , второй - без этого оператора .
7+ Create two variants: the first one using NOT ` ! ` , the second one -- without it .
Original file line number Diff line number Diff line change 1- Ответ: первое и третье выполнятся.
1+ The answer: the first and the third will execute.
22
3- Детали :
3+ Details :
44
55``` js
66// + run
7- // Выполнится
8- // Результат -1 || 0 = -1, в логическом контексте true
9- if (- 1 || 0 ) alert ( ' первое ' );
7+ // Runs.
8+ // The result of -1 || 0 = -1, truthy
9+ if (- 1 || 0 ) alert ( ' first ' );
1010
11- // Не выполнится
12- // -1 && 0 = 0, в логическом контексте false
13- if (- 1 && 0 ) alert ( ' второе ' );
11+ // Doesn't run
12+ // -1 && 0 = 0, falsy
13+ if (- 1 && 0 ) alert ( ' second ' );
1414
15- // Выполнится
16- // оператор && имеет больший приоритет, чем ||
17- // так что -1 && 1 выполнится раньше
18- // вычисления: null || -1 && 1 -> null || 1 -> 1
19- if (null || - 1 && 1 ) alert ( ' третье ' );
15+ // Executes
16+ // Operator && has a higher precedence than ||
17+ // so -1 && 1 executes first, giving us the chain:
18+ // null || -1 && 1 -> null || 1 -> 1
19+ if (null || - 1 && 1 ) alert ( ' third ' );
2020```
2121
Original file line number Diff line number Diff line change 1- # Вопрос про "if"
1+ # A question about "if"
22
33[ importance 5]
44
5- Какие из этих ` if ` верны, т.е. выполнятся?
5+ Which of these ` alert ` s are going to execute?
66
7- Какие конкретно значения будут результатами выражений в условиях ` if(...) ` ?
7+ What will be the results of the expressions inside ` if(...) ` ?
88
99``` js
10- if (- 1 || 0 ) alert ( ' первое ' );
11- if (- 1 && 0 ) alert ( ' второе ' );
12- if (null || - 1 && 1 ) alert ( ' третье ' );
10+ if (- 1 || 0 ) alert ( ' first ' );
11+ if (- 1 && 0 ) alert ( ' second ' );
12+ if (null || - 1 && 1 ) alert ( ' third ' );
1313```
1414
You can’t perform that action at this time.
0 commit comments