You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/11-logical-operators/article.md
+24-26Lines changed: 24 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -202,87 +202,85 @@ alert( null && 5 ); // null
202
202
alert( 0 && "orice s-ar întâmpla" ); // 0
203
203
```
204
204
205
-
<!-- We can also pass several values in a row. See how the first falsy one is returned:-->
206
-
De asemenea, putem oferi mai multe valori în același timp. Observați cum prima valoare falsy este returnată:
207
-
<!-- Mai verifică puțin traducerea de mai sus -->
205
+
De asemenea, pot fi folosite mai multe valori simultan. Observați cum prima valoare falsy este returnată:
208
206
209
207
```js run
210
208
alert( 1 && 2 && null && 3 ); // null
211
209
```
212
210
213
-
When all values are truthy, the last value is returned:
211
+
Dacă toate valorile sunt truthy, ultima dintre ele este returnată:
214
212
215
213
```js run
216
-
alert( 1 && 2 && 3 ); // 3, the last one
214
+
alert( 1 && 2 && 3 ); // 3, ultima
217
215
```
218
216
219
-
````smart header="Precedence of AND `&&` is higher than OR `||`"
220
-
The precedence ofAND`&&`operator is higher than OR`||`.
217
+
````smart header="Prioritatea lui ȘI `&&` este mai mare decât cea a lui ORI `||`"
218
+
Prioritatea operatorului ȘI`&&`este mai mare față de ce a lui ORI`||`.
221
219
222
-
So the code `a && b || c && d`is essentially the same as if the `&&`expressions were in parentheses:`(a && b) || (c && d)`.
220
+
Astfel, codul `a && b || c && d`este în esență exact la fel cu folosirea operatorului `&&`între paranteze:`(a && b) || (c && d)`.
223
221
````
224
222
225
-
````warn header="Don't replace `if` with `||` or `&&`"
226
-
Sometimes, people use the AND`&&`operator as a "shorter way to write `if`".
223
+
````warn header="Nu înlocuiți `if` cu `||` sau `&&`"
224
+
Uneori, oamenii folosesc operatorul ȘI`&&`pentru a scrie o formă mai scurtă de `if` statement.
227
225
228
-
For instance:
226
+
De exemplu:
229
227
230
228
```js run
231
229
let x = 1;
232
230
233
-
(x > 0) && alert( 'Greater than zero!' );
231
+
(x > 0) && alert( 'Mai mare decât zero!' );
234
232
```
235
233
236
-
The action in the right part of`&&`would execute only if the evaluation reaches it. That is, only if`(x > 0)`istrue.
234
+
Alerta din partea dreaptă a lui `&&`ajugne să fie executată doar dacă evaluarea ajunge până la ea. Adică, doar dacă if`(x > 0)`estetrue.
237
235
238
-
So we basically have an analogue for:
236
+
Astfel echivalentul este:
239
237
240
238
```js run
241
239
let x = 1;
242
240
243
-
if (x > 0) alert( 'Greater than zero!' );
241
+
if (x > 0) alert( 'Mai mare decât zero!' );
244
242
```
245
243
246
-
Although, the variant with`&&`appears shorter, `if`is more obvious and tends to be a little bit more readable. So we recommend using every construct for its purpose: use`if`if we want`if`and use `&&`if we want AND.
244
+
Deși, varianta cu `&&`pare a fi mai scurtă, varianta cu `if`statement este mai evidentă și mai ușor de citit. Așa că, recomandarea noastră este ca fiecare construcție să fie folosită pentru propriul scop: folosim`if`dacă vreum un`if`statement și folosit `&&`dacă avem nevoie de operatorul ȘI.
247
245
````
248
246
249
247
250
248
## ! (NOT)
251
249
252
-
The boolean NOT operator is represented with an exclamation sign `!`.
250
+
Operatorul boolean NU este reprezentat printrun semn de exclamare.
253
251
254
-
The syntax is pretty simple:
252
+
Sintaxa este destul de simplă:
255
253
256
254
```js
257
255
result = !value;
258
256
```
259
257
260
-
The operator accepts a single argument and does the following:
258
+
Operatorul acceptă un singur argument și face umrătoarele lucruri:
261
259
262
-
1.Converts the operand to boolean type:`true/false`.
263
-
2.Returns the inverse value.
260
+
1.Convertește operantul într-un boolean de tipul:`true/false`.
261
+
2.Returnează valoarea opusă.
264
262
265
-
For instance:
263
+
Spre exemplu:
266
264
267
265
```js run
268
266
alert( !true ); // false
269
267
alert( !0 ); // true
270
268
```
271
269
272
-
A double NOT`!!`is sometimes used for converting a value to boolean type:
270
+
Dublu NU`!!`poate fi folosit uneori pentru a converti o valoare într-un boolean.
273
271
274
272
```js run
275
273
alert( !!"non-empty string" ); // true
276
274
alert( !!null ); // false
277
275
```
278
276
279
-
That is, the first NOT converts the value to boolean and returns the inverse, and the second NOT inverses it again. In the end, we have a plain value-to-boolean conversion.
277
+
Adică, primul NU convertește valoare într-un boolean și returnează valoarea opusă, iar cel de al doilea NU inversează valoarea din nou. În final, obținem o conversie de la o valoare la un boolean.
280
278
281
-
There's a little more verbose way to do the same thing -- a built-in `Boolean` function:
279
+
Există o metodă special concepută pentru acest lucru --o funcție`Boolean`concepută expres pentru acesastă necesitate.
282
280
283
281
```js run
284
282
alert( Boolean("non-empty string") ); // true
285
283
alert( Boolean(null) ); // false
286
284
```
287
285
288
-
The precedence of NOT `!` is the highest of all logical operators, so it always executes first, before `&&` or `||`.
286
+
Prioritatea lui NU`!`este cea mai mare dintre toți operatorii logici, fiind executat mereu primul, înaintea lui `&&`sau`||`.
0 commit comments