diff --git a/1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/solution.md b/1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/solution.md index 8869d32e6..b23c7dc31 100644 --- a/1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/solution.md +++ b/1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/solution.md @@ -1,4 +1,4 @@ -The answer is `2`, that's the first truthy value. +Răpunsul este `2`, aceasta este prima valoare truthy. ```js run alert( null || 2 || undefined ); diff --git a/1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/task.md b/1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/task.md index a7c9addfc..ae44926de 100644 --- a/1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/task.md +++ b/1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/task.md @@ -2,9 +2,9 @@ importance: 5 --- -# What's the result of OR? +# Care este rezultatul lui OR? -What is the code below going to output? +Care va fi output-ul codului de mai jos? ```js alert( null || 2 || undefined ); diff --git a/1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md b/1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md index f85b56366..01592c472 100644 --- a/1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md +++ b/1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md @@ -1,13 +1,13 @@ -The answer: first `1`, then `2`. +Răspunsul: prima dată `1`, iar apoi `2`. ```js run alert( alert(1) || 2 || alert(3) ); ``` -The call to `alert` does not return a value. Or, in other words, it returns `undefined`. +Apelul către `alert` nu returnează o valoare. Sau, prin alte cuvinte, returnează `undefined`. -1. The first OR `||` evaluates its left operand `alert(1)`. That shows the first message with `1`. -2. The `alert` returns `undefined`, so OR goes on to the second operand searching for a truthy value. -3. The second operand `2` is truthy, so the execution is halted, `2` is returned and then shown by the outer alert. +1. Primul OR `||` evaluează operantul din stânga sa `alert(1)`. Aceasta afișează primul mesaj cu `1`. +2. `alert` întoarce `undefined`, așa că OR merge la al doilea operand căutând o valoare truthy. +3. Cel de al doilea operand `2` este truthy, așa că execuția este oprită, `2` este returnat fiind afișat de către `alert`-ul exterior. -There will be no `3`, because the evaluation does not reach `alert(3)`. +`3` nu va fi afișat, deoarece evaluarea nu ajunge la `alert(3)`. diff --git a/1-js/02-first-steps/11-logical-operators/2-alert-or/task.md b/1-js/02-first-steps/11-logical-operators/2-alert-or/task.md index 3908fa2ec..fa03295ba 100644 --- a/1-js/02-first-steps/11-logical-operators/2-alert-or/task.md +++ b/1-js/02-first-steps/11-logical-operators/2-alert-or/task.md @@ -2,9 +2,9 @@ importance: 3 --- -# What's the result of OR'ed alerts? +# Care este rezultatul alertelor combinate prin OR? -What will the code below output? +Care va vi output-ul codului de mai jos? ```js alert( alert(1) || 2 || alert(3) ); diff --git a/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/solution.md b/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/solution.md index 5c2455ef4..d8e19deee 100644 --- a/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/solution.md +++ b/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/solution.md @@ -1,4 +1,4 @@ -The answer: `null`, because it's the first falsy value from the list. +Răspunsul: `null`, deoarece este prima valoare falsy din listă. ```js run alert( 1 && null && 2 ); diff --git a/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md b/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md index 043d431e4..311598b22 100644 --- a/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md +++ b/1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md @@ -2,9 +2,9 @@ importance: 5 --- -# What is the result of AND? +# Care este rezultatul lui AND? -What is this code going to show? +Ce va afișa codul de mai jos? ```js alert( 1 && null && 2 ); diff --git a/1-js/02-first-steps/11-logical-operators/4-alert-and/solution.md b/1-js/02-first-steps/11-logical-operators/4-alert-and/solution.md index b6fb10d72..650d319bc 100644 --- a/1-js/02-first-steps/11-logical-operators/4-alert-and/solution.md +++ b/1-js/02-first-steps/11-logical-operators/4-alert-and/solution.md @@ -1,10 +1,9 @@ -The answer: `1`, and then `undefined`. +Răspunsul: `1`, iar apoi `undefined`. ```js run alert( alert(1) && alert(2) ); ``` -The call to `alert` returns `undefined` (it just shows a message, so there's no meaningful return). - -Because of that, `&&` evaluates the left operand (outputs `1`), and immediately stops, because `undefined` is a falsy value. And `&&` looks for a falsy value and returns it, so it's done. +Apelul către `alert` întoarce `undefined` (afișează doar un mesaj, deci nu întoarce nimic semnificativ). +Din cauza aceasta, `&&` evaluează operantul din stânga (output-ul `1`), și se oprește imediat, deoarece `undefined` este o valoare falsy. Iar `&&` caută o valoare falsy și o întoarce, deci a terminat. \ No newline at end of file diff --git a/1-js/02-first-steps/11-logical-operators/4-alert-and/task.md b/1-js/02-first-steps/11-logical-operators/4-alert-and/task.md index 69f877b95..b58746694 100644 --- a/1-js/02-first-steps/11-logical-operators/4-alert-and/task.md +++ b/1-js/02-first-steps/11-logical-operators/4-alert-and/task.md @@ -2,9 +2,9 @@ importance: 3 --- -# What is the result of AND'ed alerts? +# Care este rezultatul alertelor combinate cu AND? -What will this code show? +Ce va afișa acest cod? ```js alert( alert(1) && alert(2) ); diff --git a/1-js/02-first-steps/11-logical-operators/5-alert-and-or/solution.md b/1-js/02-first-steps/11-logical-operators/5-alert-and-or/solution.md index 25e3568f8..dec57c243 100644 --- a/1-js/02-first-steps/11-logical-operators/5-alert-and-or/solution.md +++ b/1-js/02-first-steps/11-logical-operators/5-alert-and-or/solution.md @@ -1,16 +1,15 @@ -The answer: `3`. +Răspunsul: `3`. ```js run alert( null || 2 && 3 || 4 ); ``` -The precedence of AND `&&` is higher than `||`, so it executes first. +Prioritatea lui AND `&&` este mai mare decât cea a lui OR `||`, așa că se execută primul. -The result of `2 && 3 = 3`, so the expression becomes: +Rezultatul lui `2 && 3 = 3`, așa că expresia devine: ``` null || 3 || 4 ``` -Now the result is the first truthy value: `3`. - +Acum rezultatul este prima valoare truthy: `3`. \ No newline at end of file diff --git a/1-js/02-first-steps/11-logical-operators/5-alert-and-or/task.md b/1-js/02-first-steps/11-logical-operators/5-alert-and-or/task.md index b18bb9c51..3efe5f5c1 100644 --- a/1-js/02-first-steps/11-logical-operators/5-alert-and-or/task.md +++ b/1-js/02-first-steps/11-logical-operators/5-alert-and-or/task.md @@ -2,9 +2,9 @@ importance: 5 --- -# The result of OR AND OR +# Rezultatul lui OR AND OR -What will the result be? +Care va fi rezultatul? ```js alert( null || 2 && 3 || 4 ); diff --git a/1-js/02-first-steps/11-logical-operators/6-check-if-in-range/task.md b/1-js/02-first-steps/11-logical-operators/6-check-if-in-range/task.md index fc9e336c1..ac6b172a1 100644 --- a/1-js/02-first-steps/11-logical-operators/6-check-if-in-range/task.md +++ b/1-js/02-first-steps/11-logical-operators/6-check-if-in-range/task.md @@ -2,8 +2,8 @@ importance: 3 --- -# Check the range between +# Verificați intervalul dintre -Write an `if` condition to check that `age` is between `14` and `90` inclusively. +Scrie o condiție `if` care verifică dacă `age` se încadrează între `14` și `90` inclusiv. -"Inclusively" means that `age` can reach the edges `14` or `90`. +"Inclusiv" înseamnă că `age` poate fi de asemenea `14` sau `90`. diff --git a/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/solution.md b/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/solution.md index d1946a967..192f50fa1 100644 --- a/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/solution.md +++ b/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/solution.md @@ -1,10 +1,10 @@ -The first variant: +Prima variantă: ```js if (!(age >= 14 && age <= 90)) ``` -The second variant: +A doua variantă: ```js if (age < 14 || age > 90) diff --git a/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/task.md b/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/task.md index 9b947d00f..969676f4e 100644 --- a/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/task.md +++ b/1-js/02-first-steps/11-logical-operators/7-check-if-out-range/task.md @@ -2,8 +2,8 @@ importance: 3 --- -# Check the range outside +# Verifică intervalul din afară -Write an `if` condition to check that `age` is NOT between `14` and `90` inclusively. +Scrie o condiție `if` care verifică dacă `age` NU este cuprins înte `14` și `90` inclusiv. -Create two variants: the first one using NOT `!`, the second one -- without it. +Creează două variante: în prima să folosești NOT `!`, iar în ceea de-a doua -- să nu. \ No newline at end of file diff --git a/1-js/02-first-steps/11-logical-operators/8-if-question/solution.md b/1-js/02-first-steps/11-logical-operators/8-if-question/solution.md index 210509758..77cde5d2c 100644 --- a/1-js/02-first-steps/11-logical-operators/8-if-question/solution.md +++ b/1-js/02-first-steps/11-logical-operators/8-if-question/solution.md @@ -1,20 +1,20 @@ -The answer: the first and the third will execute. +Răspuns: primul și al treilea se vor executa. -Details: +Detalii: ```js run -// Runs. -// The result of -1 || 0 = -1, truthy -if (-1 || 0) alert( 'first' ); +// Este executat. +// Rezultatul dintre -1 || 0 = -1, truthy +if (-1 || 0) alert( 'primul' ); -// Doesn't run +// Nu este executat // -1 && 0 = 0, falsy -if (-1 && 0) alert( 'second' ); +if (-1 && 0) alert( 'al doilea' ); -// Executes -// Operator && has a higher precedence than || -// so -1 && 1 executes first, giving us the chain: +// Este executat +// Oparatorul && are o prioritate mai mare decât || +// așadar -1 && 1 este exuctat mai întâi, dând lanțul următor: // null || -1 && 1 -> null || 1 -> 1 -if (null || -1 && 1) alert( 'third' ); +if (null || -1 && 1) alert( 'al treilea' ); ``` diff --git a/1-js/02-first-steps/11-logical-operators/8-if-question/task.md b/1-js/02-first-steps/11-logical-operators/8-if-question/task.md index 55987121b..5a68aa1ca 100644 --- a/1-js/02-first-steps/11-logical-operators/8-if-question/task.md +++ b/1-js/02-first-steps/11-logical-operators/8-if-question/task.md @@ -2,15 +2,15 @@ importance: 5 --- -# A question about "if" +# O întrebare despre "if" -Which of these `alert`s are going to execute? +Care dintre următoarele `alert`e se vor executa? -What will the results of the expressions be inside `if(...)`? +Care va fi rezultatul expresiilor din interiorul lui `if(...)`? ```js -if (-1 || 0) alert( 'first' ); -if (-1 && 0) alert( 'second' ); -if (null || -1 && 1) alert( 'third' ); +if (-1 || 0) alert( 'primul' ); +if (-1 && 0) alert( 'al doilea' ); +if (null || -1 && 1) alert( 'al treilea' ); ``` diff --git a/1-js/02-first-steps/11-logical-operators/9-check-login/solution.md b/1-js/02-first-steps/11-logical-operators/9-check-login/solution.md index 604606259..d43bd9d31 100644 --- a/1-js/02-first-steps/11-logical-operators/9-check-login/solution.md +++ b/1-js/02-first-steps/11-logical-operators/9-check-login/solution.md @@ -22,4 +22,4 @@ if (userName === 'Admin') { } ``` -Note the vertical indents inside the `if` blocks. They are technically not required, but make the code more readable. +Observați indentările verticale din interiorul blocului `if`. Acesta nu sunt neapărat necesare, dar fac codul mult mai lizibil. \ No newline at end of file diff --git a/1-js/02-first-steps/11-logical-operators/9-check-login/task.md b/1-js/02-first-steps/11-logical-operators/9-check-login/task.md index 290a52642..0059dbfd4 100644 --- a/1-js/02-first-steps/11-logical-operators/9-check-login/task.md +++ b/1-js/02-first-steps/11-logical-operators/9-check-login/task.md @@ -2,24 +2,24 @@ importance: 3 --- -# Check the login +# Verificați login-ul -Write the code which asks for a login with `prompt`. +Scrieți un bloc de cod care necesită logare prin `prompt`. -If the visitor enters `"Admin"`, then `prompt` for a password, if the input is an empty line or `key:Esc` -- show "Canceled", if it's another string -- then show "I don't know you". +Dacă vizitatorul introduce `"Admin"`, atunci `prompt` pentru o parolă, dacă input-ul este gol sau `key:Esc` -- afișați "Anulat", dacă este un alt string -- atunci afișați "Nu te cunosc". -The password is checked as follows: +Parola este verificată după cum umrmează: -- If it equals "TheMaster", then show "Welcome!", -- Another string -- show "Wrong password", -- For an empty string or cancelled input, show "Canceled" +- Dacă este egal cu "TheMaster", atunci afișează "Welcome!", +- Un alt string -- afișează "Parolă greșită", +- Pentru un string gol sau input-ul este anulat, afișează "Anulat", -The schema: +Schema:  -Please use nested `if` blocks. Mind the overall readability of the code. +Vă rugăm folosiți blocuri `if` nested. Aveți în vedere lizibilitatea generală a codului. -Hint: passing an empty input to a prompt returns an empty string `''`. Pressing `key:ESC` during a prompt returns `null`. +Sugestie: transmiterea unui input gol către un `prompt` returnează un string gol `''`. Apăsând `key:ESC` în timpul unui prompt returnează `null`. [demo] diff --git a/1-js/02-first-steps/11-logical-operators/article.md b/1-js/02-first-steps/11-logical-operators/article.md index 78c4fd2f1..ff21900a5 100644 --- a/1-js/02-first-steps/11-logical-operators/article.md +++ b/1-js/02-first-steps/11-logical-operators/article.md @@ -1,24 +1,24 @@ -# Logical operators +# Operatori logici -There are four logical operators in JavaScript: `||` (OR), `&&` (AND), `!` (NOT), `??` (Nullish Coalescing). Here we cover the first three, the `??` operator is in the next article. +În JavaScript există patru operatori logici: `||` (OR), `&&` (AND), `!` (NOT), `??` (Nullish Coalescing). Aici vorbim doar despre primii trei, operatorul `??` va fi acoperit în următorul articol. -Although they are called "logical", they can be applied to values of any type, not only boolean. Their result can also be of any type. +Chiar dacă sunt denumiți "logici", aceștia pot fi folosiți pentru valori de orice tip, nu doar pentru cele de tip boolean. Rezultatul acestora putând fi de orice tip. -Let's see the details. +Haideți să aflăm mai multe detalii. ## || (OR) -The "OR" operator is represented with two vertical line symbols: +Simbolul pentru operatorul "OR" este reprezentat prin două linii verticale. ```js result = a || b; ``` -In classical programming, the logical OR is meant to manipulate boolean values only. If any of its arguments are `true`, it returns `true`, otherwise it returns `false`. +În programarea clasică, operatorul logic "OR" este folosit pentru a manipula doar valori de tip boolean. Dacă valoarea unuia dintre argumentele acestuia este `true`, rezultatul operației va fi `true`, în caz contrar rezultatul va fi `false`. -In JavaScript, the operator is a little bit trickier and more powerful. But first, let's see what happens with boolean values. +În JavaScript, acest operator este puțin mai complex, dar și mult mai eficient. Pentru început, haideți să vedem ce se întâmplă cu aceste valori de tip boolean. -There are four possible logical combinations: +Pot fi posibile doar patru combinații. ```js run alert( true || true ); // true @@ -27,21 +27,21 @@ alert( true || false ); // true alert( false || false ); // false ``` -As we can see, the result is always `true` except for the case when both operands are `false`. +După cum putem vedea, rezultat este mereu `true` cu excepția cazului în care ambii operanți au valoarea `false`. -If an operand is not a boolean, it's converted to a boolean for the evaluation. +Dacă un operant nu este de tip boolean, acesta este convertit automat pentru a putea fi evaluat. -For instance, the number `1` is treated as `true`, the number `0` as `false`: +De exemplu, numărul `1` este tratat ca `true`, iar numărul `0` ca `false`: ```js run -if (1 || 0) { // works just like if( true || false ) +if (1 || 0) { // funcționează exact ca if( true || false ) alert( 'truthy!' ); } ``` -Most of the time, OR `||` is used in an `if` statement to test if *any* of the given conditions is `true`. +De cele mai multe ori, OR `||` este folosit într-un `if` statement pentru a testa dacă *vreuna* dintre condițiile date este `true`. -For example: +Spre exemplu: ```js run let hour = 9; @@ -49,61 +49,61 @@ let hour = 9; *!* if (hour < 10 || hour > 18) { */!* - alert( 'The office is closed.' ); + alert( 'Biroul este închis.' ); } ``` -We can pass more conditions: +Putem adăuga mai multe condiții: ```js run let hour = 12; let isWeekend = true; if (hour < 10 || hour > 18 || isWeekend) { - alert( 'The office is closed.' ); // it is the weekend + alert( 'Biroul este închis.' ); // este weekend } ``` -## OR "||" finds the first truthy value [#or-finds-the-first-truthy-value] +## OR "||" identifică prima valoare truthy [#or-finds-the-first-truthy-value] -The logic described above is somewhat classical. Now, let's bring in the "extra" features of JavaScript. +Logica descrisă mai sus este oarecum clasică. Haideți să discutăm despre caracteristicile "extra" din JavaScript. -The extended algorithm works as follows. +Algoritmul extins funcționează după cum urmează. -Given multiple OR'ed values: +Sunt date mai multe valori ale lui OR. ```js result = value1 || value2 || value3; ``` -The OR `||` operator does the following: +Operatorul OR `||` face următoarele: -- Evaluates operands from left to right. -- For each operand, converts it to boolean. If the result is `true`, stops and returns the original value of that operand. -- If all operands have been evaluated (i.e. all were `false`), returns the last operand. +- Evaluzează operanzii de la stânga spre dreapta. +- Fiecare operand este convertit într-o valoare boolean. Dacă rezultatul este `true`, execuția este oprită și valoarea originală a acelui operand este returnată. +- Dacă toți operanzii au fost evaluați (iar toți erau `false`), ultimul operant este returnat. -A value is returned in its original form, without the conversion. +O valoare este returnată în forma ei originală, fără conversiune. -In other words, a chain of OR `||` returns the first truthy value or the last one if no truthy value is found. +Cu alte cuvinte, într-un lanț de operatori logici OR `||` este returnată prima valoare truthy sau ultima dacă nicio valoare truthy nu este identificată. -For instance: +Spre exemplu: ```js run -alert( 1 || 0 ); // 1 (1 is truthy) +alert( 1 || 0 ); // 1 (1 este truthy) -alert( null || 1 ); // 1 (1 is the first truthy value) -alert( null || 0 || 1 ); // 1 (the first truthy value) +alert( null || 1 ); // 1 (1 este prima valoare truthy) +alert( null || 0 || 1 ); // 1 (prima valoare truthy) -alert( undefined || null || 0 ); // 0 (all falsy, returns the last value) +alert( undefined || null || 0 ); // 0 (toate valorile sunt falsy, ultima valoare este returnată) ``` -This leads to some interesting usage compared to a "pure, classical, boolean-only OR". +Asta conduce la utilizări mai interesante față de cele pur clasice în care operatorul OR compară doar valori boolean. -1. **Getting the first truthy value from a list of variables or expressions.** +1. **Obținerea primei valori truthy dintr-o listă de variabile sau expresii.** - For instance, we have `firstName`, `lastName` and `nickName` variables, all optional (i.e. can be undefined or have falsy values). + Spre exemplu, avem variabilele `firstName`, `lastName` și `nickName`, toate opționale (adică valoarea lor poate fi undefined sau falsy) - Let's use OR `||` to choose the one that has the data and show it (or `"Anonymous"` if nothing set): + Haideți să folosim operatorul OR `||` pentru a identifica variabila truthy și să folosim conținutul acesteia (sau `"Anonim"` în caz contrar): ```js run let firstName = ""; @@ -111,40 +111,40 @@ This leads to some interesting usage compared to a "pure, classical, boolean-onl let nickName = "SuperCoder"; *!* - alert( firstName || lastName || nickName || "Anonymous"); // SuperCoder + alert( firstName || lastName || nickName || "Anonim"); // SuperCoder */!* ``` - If all variables were falsy, `"Anonymous"` would show up. + Dacă toate variabilele ar fi fost falsy, ar fi fost folosit `"Anonim"`. -2. **Short-circuit evaluation.** +2. **Evaluarea de tip scurt circuit.** - Another feature of OR `||` operator is the so-called "short-circuit" evaluation. + O altă caracteristică a operatorului OR `||` este așa numita evaluare de tip scurt circuit. - 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. + Aceasta înseamnă că `||` își procesează argumentele până când prima valoare truthy este întâlnită, iar apoi acea valoare este returnată imediat, fără ca celălalt argument să mai fie luat în considerare. - 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. + Importanța acestei caracteristici începe să devină evidentă în momentul în care unul dintre operanți nu conține doar o valoare, ci o expresie care aduce cu sine și un efect advers, cum ar fi atribuirea valorii unei variabile sau invocarea unei funcții. - In the example below, only the second message is printed: + Pentru exemplul de mai jos, doar al doilea mesaj este afișat: ```js run no-beautify - *!*true*/!* || alert("not printed"); - *!*false*/!* || alert("printed"); + *!*true*/!* || alert("Acest mesaj nu este printat!"); + *!*false*/!* || alert("Acest mesaj este printat!"); ``` - In the first line, the OR `||` operator stops the evaluation immediately upon seeing `true`, so the `alert` isn't run. + În prima linie, operatorul OR `||` imediat ce întâlnește valoarea `true` oprește evaluarea, astfel încât metoda `alert` nu este executată. - Sometimes, people use this feature to execute commands only if the condition on the left part is falsy. + Uneori, oamenii folosesc această funcție pentru a executa comenzi doar dacă condiția din partea stângă este falsy. ## && (AND) -The AND operator is represented with two ampersands `&&`: +Operatorul ȘI este reprezentat de două semne ampersand `&&`: ```js result = a && b; ``` -In classical programming, AND returns `true` if both operands are truthy and `false` otherwise: +În programarea clasică, operatorul ȘI are ca rezultat `true` dacă ambii operanți sunt truthy și `false` în caz contrar: ```js run alert( true && true ); // true @@ -153,137 +153,137 @@ alert( true && false ); // false alert( false && false ); // false ``` -An example with `if`: +Un exemplu cu `if`: ```js run let hour = 12; let minute = 30; - + if (hour == 12 && minute == 30) { - alert( 'The time is 12:30' ); + alert( 'Este ora 12:30' ); } ``` -Just as with OR, any value is allowed as an operand of AND: +La fel cum se întâmplă cu operatorul ORI, ȘI poate accepta ca operant orice valoare: ```js run -if (1 && 0) { // evaluated as true && false - alert( "won't work, because the result is falsy" ); +if (1 && 0) { // evaluat ca true && false + alert( "nu va funcționa, din cauză că rezultatul este falsy" ); } ``` -## AND "&&" finds the first falsy value +## AND "&&" identifică prima valoare falsy -Given multiple AND'ed values: +Sunt date mai multe valori conectate prin operatorul logic ȘI: ```js result = value1 && value2 && value3; ``` -The AND `&&` operator does the following: +Operatorul AND `&&` face următoarele lucruri: -- Evaluates operands from left to right. -- For each operand, converts it to a boolean. If the result is `false`, stops and returns the original value of that operand. -- If all operands have been evaluated (i.e. all were truthy), returns the last operand. +- Evaluează operanții de la stânga la dreapta. +- Convertește fiecare operant într-un boolean. Dacă rezultatul este `false`, procesul este oprit, iar valoarea originală a operantului este returnată. +- Dacă toți operanții au fost evaluați (și toți sunt truthy), ultimul operant este returnat. -In other words, AND returns the first falsy value or the last value if none were found. +Cu alte cuvinte, operatorul ȘI are ca rezultat prima valoare falsy sau ultima valoare dacă niciuna nu este falsy. -The rules above are similar to OR. The difference is that AND returns the first *falsy* value while OR returns the first *truthy* one. +Regulile de mai sus sunt similare și pentru ORI. Diferența constă în faptul că ȘI are ca rezultat prima valoare *falsy* în timp ce ORI are ca rezultat prima valoare *truthy*. -Examples: +Exemple: ```js run -// if the first operand is truthy, -// AND returns the second operand: +// dacă primul operant este truthy, +// ȘI are ca rezultat cel de al doilea operant: alert( 1 && 0 ); // 0 alert( 1 && 5 ); // 5 -// if the first operand is falsy, -// AND returns it. The second operand is ignored +// dacă primul operant este falsy, +// acesta este rezultatul lui ȘI, iar cel de al doilea este ignorat alert( null && 5 ); // null -alert( 0 && "no matter what" ); // 0 +alert( 0 && "orice s-ar întâmpla" ); // 0 ``` -We can also pass several values in a row. See how the first falsy one is returned: +De asemenea, pot fi folosite mai multe valori simultan. Observați cum prima valoare falsy este returnată: ```js run alert( 1 && 2 && null && 3 ); // null ``` -When all values are truthy, the last value is returned: +Dacă toate valorile sunt truthy, ultima dintre ele este returnată: ```js run -alert( 1 && 2 && 3 ); // 3, the last one +alert( 1 && 2 && 3 ); // 3, ultima ``` -````smart header="Precedence of AND `&&` is higher than OR `||`" -The precedence of AND `&&` operator is higher than OR `||`. +````smart header="Prioritatea lui AND `&&` este mai mare decât cea a lui ORI `||`" +Prioritatea operatorului AND `&&` este mai mare față de ce a lui ORI `||`. -So the code `a && b || c && d` is essentially the same as if the `&&` expressions were in parentheses: `(a && b) || (c && d)`. +Astfel, codul `a && b || c && d` este în esență exact la fel cu folosirea operatorului `&&` între paranteze: `(a && b) || (c && d)`. ```` -````warn header="Don't replace `if` with `||` or `&&`" -Sometimes, people use the AND `&&` operator as a "shorter way to write `if`". +````warn header="Nu înlocuiți `if` cu `||` sau `&&`" +Uneori, oamenii folosesc operatorul AND `&&` pentru a scrie o formă mai scurtă de `if` statement. -For instance: +De exemplu: ```js run let x = 1; -(x > 0) && alert( 'Greater than zero!' ); +(x > 0) && alert( 'Mai mare decât zero!' ); ``` -The action in the right part of `&&` would execute only if the evaluation reaches it. That is, only if `(x > 0)` is true. +Acțiunea din partea dreaptă a lui `&&` ajunge să fie executată doar dacă evaluarea ajunge până la ea. Adică, doar dacă if `(x > 0)` este true. -So we basically have an analogue for: +Astfel echivalentul este: ```js run let x = 1; -if (x > 0) alert( 'Greater than zero!' ); +if (x > 0) alert( 'Mai mare decât zero!' ); ``` -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. +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. ```` ## ! (NOT) -The boolean NOT operator is represented with an exclamation sign `!`. +Operatorul boolean NOT este reprezentat printrun semn de exclamare. -The syntax is pretty simple: +Sintaxa este destul de simplă: ```js result = !value; ``` -The operator accepts a single argument and does the following: +Operatorul acceptă un singur argument și face umrătoarele lucruri: -1. Converts the operand to boolean type: `true/false`. -2. Returns the inverse value. +1. Convertește operantul într-un boolean de tipul: `true/false`. +2. Returnează valoarea opusă. -For instance: +Spre exemplu: ```js run alert( !true ); // false alert( !0 ); // true ``` -A double NOT `!!` is sometimes used for converting a value to boolean type: +Dublu NOT `!!` poate fi folosit uneori pentru a converti o valoare într-un boolean. ```js run alert( !!"non-empty string" ); // true alert( !!null ); // false ``` -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. +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. -There's a little more verbose way to do the same thing -- a built-in `Boolean` function: +Există o metodă special concepută pentru acest lucru -- o funcție `Boolean` concepută expres pentru acesastă necesitate. ```js run alert( Boolean("non-empty string") ); // true alert( Boolean(null) ); // false ``` -The precedence of NOT `!` is the highest of all logical operators, so it always executes first, before `&&` or `||`. +Prioritatea lui NOT `!` este cea mai mare dintre toți operatorii logici, fiind executat mereu primul, înaintea lui `&&` sau `||`. \ No newline at end of file