Skip to content

Commit bbfdd3d

Browse files
committed
saving progress
1 parent d3fa813 commit bbfdd3d

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

  • 1-js/02-first-steps/11-logical-operators

1-js/02-first-steps/11-logical-operators/article.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,39 +101,39 @@ alert( undefined || null || 0 ); // 0 (усі не правдиві, повер
101101

102102
1. **Отримання першого правдивого значення зі списку змінних або виразів.**
103103

104-
Imagine we have a list of variables which can either contain data or be `null/undefined`. How can we find the first one with data?
104+
Уявіть, що у нас є список змінних, які можуть містити дані убо бути `null/undefined`. Як знайти першу змінну за даними?
105105

106-
We can use OR `||`:
106+
Ми можемо використати OR `||`:
107107

108108
```js run
109109
let currentUser = null;
110-
let defaultUser = "John";
110+
let defaultUser = "Іван";
111111

112112
*!*
113113
let name = currentUser || defaultUser || "unnamed";
114114
*/!*
115115

116-
alert( name ); // selects "John" – the first truthy value
116+
alert( name ); // обере "Іван" – перше правдиве значення
117117
```
118118

119-
If both `currentUser` and `defaultUser` were falsy, `"unnamed"` would be the result.
120-
2. **Short-circuit evaluation.**
119+
Якщо і `currentUser`, і `defaultUser` були б не правдивими, `"unnamed"` було б результатом.
120+
2. **Обчислення короткого змичання.**
121121

122-
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. This process is called "a short-circuit evaluation" because it goes as short as possible from left to right.
122+
Операндами можуть бути не тільки значення, але й довільні вирази. OR обчислює Цей процес називається "обчисленням короткого замикання", оскільки він іде якомога коротше зліва направо.
123123

124-
This is clearly seen when the expression given as the second argument has a side effect like a variable assignment.
124+
Це чітко видно, коли вираз, заданий як другий аргумент, має побічний ефект, як присвоєння змінної.
125125

126-
In the example below, `x` does not get assigned:
126+
У наведеному нижче прикладі `x` не присвоюється значення:
127127

128128
```js run no-beautify
129129
let x;
130130
131131
*!*true*/!* || (x = 1);
132132
133-
alert(x); // undefined, because (x = 1) not evaluated
133+
alert(x); // undefined, оскільки (x = 1) не був обчислений
134134
```
135135

136-
If, instead, the first argument is `false`, `||` evaluates the second one, thus running the assignment:
136+
Якщо замість цього перший аргумент є `false`, `||` обчислює другий, таким чином виконуючи присвоєння:
137137

138138
```js run no-beautify
139139
let x;
@@ -143,7 +143,7 @@ alert( undefined || null || 0 ); // 0 (усі не правдиві, повер
143143
alert(x); // 1
144144
```
145145

146-
An assignment is a simple case. There may be side effects, that won't show up if the evaluation doesn't reach them.
146+
Присвоєння — це простий випадок. Можливі побічні ефекти, які не з'являтимуться, якщо обчислення не досяген їх.
147147
148148
As we can see, such a use case is a "shorter way of doing `if`". The first operand is converted to boolean. If it's false, the second one is evaluated.
149149

0 commit comments

Comments
 (0)