@@ -60,46 +60,46 @@ let hour = 12;
6060let isWeekend = true ;
6161
6262if (hour < 10 || hour > 18 || isWeekend) {
63- alert ( ' Офіс зачинений.' ); // цу вихідні
63+ alert ( ' Офіс зачинений.' ); // це вихідні
6464}
6565```
6666
67- ## OR finds the first truthy value
67+ ## OR знаходить перше правдиве значенн
6868
69- The logic described above is somewhat classical. Now, let's bring in the "extra" features of JavaScript.
69+ Описана вище логіка дещо класична. Тепер давайте введемо "додаткові" особливості JavaScript.
7070
71- The extended algorithm works as follows .
71+ Розширений алгоритм працює наступним чином .
7272
73- Given multiple OR'ed values :
73+ Дано кілька значень, розділених опертором OR :
7474
7575``` js
7676result = value1 || value2 || value3;
7777```
7878
79- The OR ` || ` operator does the following :
79+ Оператор OR ` || ` робить наступне :
8080
81- - Evaluates operands from left to right .
82- - For each operand, converts it to boolean. If the result is ` true ` , stops and returns the original value of that operand .
83- - If all operands have been evaluated (i.e. all were ` false ` ), returns the last operand .
81+ - Обчислює операнди зліва направо .
82+ - Перетворює значення кожного операнда на булеве. Якщо результат ` true ` , зупиняється і повертає початкове значення цього операнда .
83+ - Якщо всі операнди були обчисленні (тобто усі були ` false ` ), повертає останній операнд .
8484
85- A value is returned in its original form, without the conversion .
85+ Значення повертається у первісному вигляді без конвертації .
8686
87- In other words, a chain of OR ` "||" ` returns the first truthy value or the last one if no truthy value is found .
87+ Іншими словами, ланцюжок с OR ` "||" ` повертає перше правдиве значення або останнє, якщо не знайдено правдивого значення .
8888
89- For instance :
89+ Наприклад :
9090
9191``` js run
92- alert ( 1 || 0 ); // 1 (1 is truthy )
93- alert ( true || ' no matter what' ); // (true is truthy )
92+ alert ( 1 || 0 ); // 1 (1 є правдивим )
93+ alert ( true || ' no matter what' ); // (true є правдивим )
9494
95- alert ( null || 1 ); // 1 (1 is the first truthy value )
96- alert ( null || 0 || 1 ); // 1 (the first truthy value )
97- alert ( undefined || null || 0 ); // 0 (all falsy, returns the last value )
95+ alert ( null || 1 ); // 1 (1 є першим правдивим значенням )
96+ alert ( null || 0 || 1 ); // 1 (перше правдиве значення )
97+ alert ( undefined || null || 0 ); // 0 (усі не правдиві, повертає останнє значення )
9898```
9999
100- This leads to some interesting usage compared to a "pure, classical, boolean-only OR".
100+ Це призводить до цікавого використання у порівнянни з "чистим, класичним, виключно-булевим OR".
101101
102- 1 . ** Getting the first truthy value from a list of variables or expressions .**
102+ 1 . ** Отримання першого правдивого значення зі списку змінних або виразів .**
103103
104104 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?
105105
0 commit comments