Skip to content

Commit 3c92cb3

Browse files
committed
translation to line 126
1 parent 111c08e commit 3c92cb3

File tree

1 file changed

+33
-30
lines changed
  • 1-js/02-first-steps/11-logical-operators

1 file changed

+33
-30
lines changed

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

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,94 +33,97 @@ Dacă un operant nu este de tip boolean, acesta este convertit automat într-unu
3333
De exemplu, numărul „1” este tratat ca fiind „adevărat”, iar numărul „0” este „fals”:
3434

3535
```js run
36-
if (1 || 0) { // funcționează asemenea lui if( adevărat || false )
36+
if (1 || 0) { // funcționează asemenea lui if( adevărat || fals )
3737
alert( 'efectiv adevărat!' );
3838
}
3939
```
4040

41-
Most of the time, OR `||` is used in an `if` statement to test if *any* of the given conditions is `true`.
41+
De cele mai multe ori, semnul ORI `||` este folositi într-un if statement pentru a testa dacă vreauna dintre condiții este adevărată.
4242

43-
For example:
43+
Spre exemplu:
4444

4545
```js run
4646
let hour = 9;
4747

4848
*!*
4949
if (hour < 10 || hour > 18) {
5050
*/!*
51-
alert( 'The office is closed.' );
51+
alert( 'Biroul este închis.' );
5252
}
5353
```
5454

55-
We can pass more conditions:
55+
Putem adăuga mai multe condiții:
5656

5757
```js run
5858
let hour = 12;
5959
let isWeekend = true;
6060

6161
if (hour < 10 || hour > 18 || isWeekend) {
62-
alert( 'The office is closed.' ); // it is the weekend
62+
alert( 'Biroul este închis.' ); // este weekend.
6363
}
6464
```
6565

66-
## OR "||" finds the first truthy value [#or-finds-the-first-truthy-value]
66+
## ORI "||" identifică prima valoare efectiv adevărată [#or-finds-the-first-truthy-value]
6767

68-
The logic described above is somewhat classical. Now, let's bring in the "extra" features of JavaScript.
68+
Logica descrisă mai sus este oarecum clasică. Haideți să discutăm despre calitățile „extra” din JavaScript.
6969

70-
The extended algorithm works as follows.
70+
Algoritmul extinds funcționează după cum urmează.
7171

72-
Given multiple OR'ed values:
72+
Sunt date mai multe valori ale lui ORI.
7373

7474
```js
7575
result = value1 || value2 || value3;
7676
```
7777

78-
The OR `||` operator does the following:
78+
Operatorul ORI `||` face următoarele lucruri:
7979

80-
- Evaluates operands from left to right.
81-
- For each operand, converts it to boolean. If the result is `true`, stops and returns the original value of that operand.
82-
- If all operands have been evaluated (i.e. all were `false`), returns the last operand.
80+
- Evaluzează operanții de la stânga spre dreapta.
81+
- Fiecare operant este convertit într-o valoare de tip boolean. Dacă rezultatul este „adevărat”, execuția se oprește și valoarea originală a acelui operant este returnată.
82+
- Dacă toți operanții au fost evaluați (iar toți erau falși), ultimul operant este returnat.
8383

84-
A value is returned in its original form, without the conversion.
84+
O valoare este returnată în forma ei originală, fără conversiune.
8585

86-
In other words, a chain of OR `||` returns the first truthy value or the last one if no truthy value is found.
86+
Cu alte cuvinte, într-un lanț de ORI `||` este returnată prima valoare efectiv adevărată sau ultima dacă nicio valoare efectiv adevărată nu este găsită.
8787

88-
For instance:
88+
Spre exemplu:
8989

9090
```js run
91-
alert( 1 || 0 ); // 1 (1 is truthy)
91+
alert( 1 || 0 ); // 1 (1 este efectiv adevărat)
9292

93-
alert( null || 1 ); // 1 (1 is the first truthy value)
94-
alert( null || 0 || 1 ); // 1 (the first truthy value)
93+
alert( null || 1 ); // 1 (1 este prima valoare efectiv adevărată)
94+
alert( null || 0 || 1 ); // 1 (prima valoare efectiv adevărată)
9595

96-
alert( undefined || null || 0 ); // 0 (all falsy, returns the last value)
96+
alert( undefined || null || 0 ); // 0 (toate valorile sunt efectiv false, este returnată ultima valoare)
9797
```
9898

99-
This leads to some interesting usage compared to a "pure, classical, boolean-only OR".
99+
Asta conduce la o utilizate mai interesantă spre deosebire de un boolean clasic de tip ORI.
100100

101-
1. **Getting the first truthy value from a list of variables or expressions.**
101+
1. **Poate fi obținută prima valoare efectiv adevărată dintr-o listă de variabile sau expresii.**
102102

103-
For instance, we have `firstName`, `lastName` and `nickName` variables, all optional (i.e. can be undefined or have falsy values).
103+
Spre exemplu, avem variabilele `firstName`, `lastName` si `nickName`, toate opționale (adică pot fi undefined sau pot avea valori efectiv false)
104104

105-
Let's use OR `||` to choose the one that has the data and show it (or `"Anonymous"` if nothing set):
105+
Hai să folosim operatorul ORI `||` pentru a selecta variabila care conține date și să le facem să apară (sau `"Anonim"` dacă niciuna nu are nicio valoare):
106106

107107
```js run
108108
let firstName = "";
109109
let lastName = "";
110110
let nickName = "SuperCoder";
111111

112112
*!*
113-
alert( firstName || lastName || nickName || "Anonymous"); // SuperCoder
113+
alert( firstName || lastName || nickName || "Anonim"); // SuperCoder
114114
*/!*
115115
```
116116

117-
If all variables were falsy, `"Anonymous"` would show up.
117+
<!-- If all variables were falsy, `"Anonymous"` would show up. -->
118+
Dacă toate variabilele ar fi efectiv false, ar apărea textul `"Anonim"`.
118119

119-
2. **Short-circuit evaluation.**
120+
2. **Evaulare de tip scurt circuit**
120121

121-
Another feature of OR `||` operator is the so-called "short-circuit" evaluation.
122+
O altă caracteristică a operatorului ORI `||` este așa numita evaluare de tip scurt circuit.
122123

123-
It means that `||` processes its arguments until the first truthy value is reached, and then the value is returned immediately, without even touching the other argument.
124+
<!-- It means that `||` processes its arguments until the first truthy value is reached, and then the value is returned immediately, without even touching the other argument. -->
125+
Aceasta înseamnă că `||` își procesează argumentele până când prima valoare efectiv adevărată este întâlnită, iar apoi acea valoare este returnată imediat, fără ca restul argumentelor să mai fie luate în considerate.
126+
<!-- Mai îmbunătățește traducere de mai sus! -->
124127

125128
The importance of this feature becomes obvious if an operand isn't just a value, but an expression with a side effect, such as a variable assignment or a function call.
126129

0 commit comments

Comments
 (0)