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..f37a0aa9b 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. +Atsakymas yra `2`, pirmoji truthy vertė. ```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..3ab89d93c 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? +# Koks bus ARBA rezultatas? -What is the code below going to output? +Ką atiduos žemiau esantis kodas? ```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 8f4d664e8..5f245ea4c 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`. +Atsakymas yra: pirma `1`, tada `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`. +Šaukimas `alert` negrąžina jokios vertės. Arba kitaip sakant, jis grąžina `undefined`. -1. The first OR `||` evaluates it's 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. Pirmasis ARBA `||` įvertina kairėje esantį operandą `alert(1)`. Jis parodo žinutę su `1`. +2. `alert` grąžina `undefined`, tad ARBA eina prie sekančio operando ieškodamas truthy vertės. +3. Antrasis operandas `2` yra truthy, tad operacija sustabdoma, grąžinamas `2` ir parodomas per išorinį alert. -There will be no `3`, because the evaluation does not reach `alert(3)`. +Nebebus `3`, nes įvertinimas nepasiekia `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..6c1145686 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? +# Koks bus ARBA alert rezultatas? -What will the code below output? +Ką atiduos žemiau esantis kodas? ```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..6fc02355f 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. +Atsakymas: `null`, nes tai yra pirmoji falsy vertė sąraše. ```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..9ddb4739e 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? +# Koks yra IR rezultatas? -What is this code going to show? +Ką parodys žemiau esantis kodas? ```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..4967d56f3 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,10 @@ -The answer: `1`, and then `undefined`. +Atsakymas: `1`, ir tada `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). +Šaukimas `alert` grąžina `undefined` (tiesiog parodo žinutę, tad nebus prasmingo grąžinimo). -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. +Dėl to `&&` įvertina kairį operandą (parodo `1`), ir iš karto sustoja, nes `undefined` yra falsy vertė. O `&&` ieško falsy vertės ir ją grąžina, ir sustoja. 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..55b84cc7a 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? +# Koks yra IR alerts rezultatas? -What will this code show? +Kas parodys kodas esantis žemiau? ```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..aecc5ef0d 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,16 @@ -The answer: `3`. +Atsakymas: `3`. ```js run alert( null || 2 && 3 || 4 ); ``` -The precedence of AND `&&` is higher than `||`, so it executes first. +IR `&&` pirmenybė yra aukštesnė už `||`, tad jis įvykdomas pirmiau. -The result of `2 && 3 = 3`, so the expression becomes: +Rezultatas yra `2 && 3 = 3`, tad išraiška tampa: ``` null || 3 || 4 ``` -Now the result is the first truthy value: `3`. +Dabar rezultatas yra pirmoji truthy vertė: `3`. 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..80434e263 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 +# ARBA IR ARBA rezultatas -What will the result be? +Koks bus rezultatas? ```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 cc00ca9fc..8999dbb78 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 +# Patikrinkite intervalą -Write an "if" condition to check that `age` is between `14` and `90` inclusively. +Parašykite "if" sąlygą, kuri patikrintų ar `age` yra tarp `14` ir `90` įskaitant. -"Inclusively" means that `age` can reach the edges `14` or `90`. +"Įskaitant" reiškia, kad `age` gali pasiekti `14` ir `90` ribas. 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..6019dd8eb 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: +Pirmas variantas: ```js if (!(age >= 14 && age <= 90)) ``` -The second variant: +Antras variantas: ```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 7c22d6ad1..5787cc419 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 +# Patikrinkite už intervalo ribų -Write an `if` condition to check that `age` is NOT between 14 and 90 inclusively. +Parašykite `if` sąlygą, kuri patikrintų ar `age` nėra tarp 14 ir 90 įskaitant. -Create two variants: the first one using NOT `!`, the second one -- without it. +Sukurkite du variantus: vieną naudojant NE `!`, kitą nenaudojant jo. 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..10f5cd004 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. +Atsakymas: pirma ir antra bus įvykdytos. Details: ```js run -// Runs. -// The result of -1 || 0 = -1, truthy -if (-1 || 0) alert( 'first' ); +// Paleidžiama. +// Rezultatas iš -1 || 0 = -1, truthy +if (-1 || 0) alert( 'pirmas' ); -// Doesn't run +// Nepaleidžiamas // -1 && 0 = 0, falsy -if (-1 && 0) alert( 'second' ); +if (-1 && 0) alert( 'antras' ); -// Executes -// Operator && has a higher precedence than || -// so -1 && 1 executes first, giving us the chain: +// Įvykdomas +// Operatorius && turi aukštesnį prioritetą negu || +// tad -1 && 1 įvykdomas pirmiau, sukurdamas mums grandinę: // null || -1 && 1 -> null || 1 -> 1 -if (null || -1 && 1) alert( 'third' ); +if (null || -1 && 1) alert( 'trečias' ); ``` 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..0c1c2f8cf 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" +# Klausimas apie "if" -Which of these `alert`s are going to execute? +Kurie iš šių `alert`s bus įvykdyti? -What will the results of the expressions be inside `if(...)`? +Koks bus išraiškų rezultatas viduje `if(...)`? ```js -if (-1 || 0) alert( 'first' ); -if (-1 && 0) alert( 'second' ); -if (null || -1 && 1) alert( 'third' ); +if (-1 || 0) alert( 'pirmas' ); +if (-1 && 0) alert( 'antras' ); +if (null || -1 && 1) alert( 'trečias' ); ``` diff --git a/1-js/02-first-steps/11-logical-operators/9-check-login/ifelse_task.svg b/1-js/02-first-steps/11-logical-operators/9-check-login/ifelse_task.svg index cbc8c7840..1c45adeaf 100644 --- a/1-js/02-first-steps/11-logical-operators/9-check-login/ifelse_task.svg +++ b/1-js/02-first-steps/11-logical-operators/9-check-login/ifelse_task.svg @@ -1 +1 @@ - \ No newline at end of file + 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 a30db7aae..58898b294 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 @@ -1,25 +1,25 @@ ```js run demo -let userName = prompt("Who's there?", ''); +let userName = prompt("Kas čia?", ''); if (userName == 'Admin') { - let pass = prompt('Password?', ''); + let pass = prompt('Slaptažodis?', ''); if (pass == 'TheMaster') { - alert( 'Welcome!' ); + alert( 'Sveiki!' ); } else if (pass == '' || pass == null) { - alert( 'Canceled' ); + alert( 'Atšaukta' ); } else { - alert( 'Wrong password' ); + alert( 'Neteisingas slaptažodis' ); } } else if (userName == '' || userName == null) { - alert( 'Canceled' ); + alert( 'Atšaukta' ); } else { - alert( "I don't know you" ); + alert( "Aš jūsų nepažįstu" ); } ``` -Note the vertical indents inside the `if` blocks. They are technically not required, but make the code more readable. +Atkreipkite dėmesį į vertikalius įgilėjimus viduje `if` rinkinio. Techniškai jie nėra būtini, bet jie paverčia kodą lengviau skaitomu. 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..9a8ff28f2 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 +# Patikrinti prisijungimą -Write the code which asks for a login with `prompt`. +Parašykite kodą, kuris prašo prisijungimo su `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". +Jeigu lankytojas įveda `"Admin"`, tada `prompt` slaptažodžio, jeigu įvedama tuščia eilė arba paspaudžiamas `key:Esc` -- parodyti "Atšaukta", jeigu tai kitokia eilutė -- tada parodyti "Aš jūsų nežinau". -The password is checked as follows: +Slaptažodis patikrinamas sekančiais žingsniais: -- If it equals "TheMaster", then show "Welcome!", -- Another string -- show "Wrong password", -- For an empty string or cancelled input, show "Canceled" +- Jeigu lygus "TheMaster", parodyti "Sveiki!", +- Kitokia eilutė -- parodyti "Neteisingas slaptažodis", +- Tuščiai eilutei arba jeigu buvo atšauktas, parodyti "Atšauktas" -The schema: +Diagrama:  -Please use nested `if` blocks. Mind the overall readability of the code. +Prašau, naudokite įdėtinius (ang. "nested") `if` rinkinius. Prižiūrėkite skaitomumą viso kodo -Hint: passing an empty input to a prompt returns an empty string `''`. Pressing `key:ESC` during a prompt returns `null`. +Patarimas: praleidžiant tuščią įvestį per prompt grąžina tuščią eilutę `''`. Paspaudžiant `key:ESC` per prompt grąžina `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 25f8ff7f5..1dbec4e4a 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 +# Loginiai operatoriai -There are three logical operators in JavaScript: `||` (OR), `&&` (AND), `!` (NOT). +JavaScript yra trys loginiai operatoriai: `||` (OR - arba), `&&` (AND - ir), `!` (NOT - ne). -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. +Nors jie vadinami "loginiais", juos galima naudoti su bet kokio tipo vertėmis, ne vien loginėmis. Jų rezultatas taip pat gali būti bet kokio tipo. -Let's see the details. +Pažiūrėkime detaliau. ## || (OR) -The "OR" operator is represented with two vertical line symbols: +Dvi vertikalios linijos atstoja "ARBA" operatorių: ```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`. +Klasikiniame programavime, loginis ARBA yra skirtas manipuliuoti tik logines vertes. Jeigu bent vienas jo argumentas yra `true`, tai ir jis grąžina `true`, kitu atveju grąžina `false`. -In JavaScript, the operator is a little bit trickier and more powerful. But first, let's see what happens with boolean values. +JavaScript operatorius yra šiek tiek sudėtingesnis ir galingesnis. Bet visų pirma pažvelkime kas nutinka su loginėmis vertėmis. -There are four possible logical combinations: +Yra keturios įmanomos loginės kombinacijos: ```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`. +Kaip matome, rezultatas yra visada `true` išskyrus kai abu operandai yra `false`. -If an operand is not a boolean, it's converted to a boolean for the evaluation. +Jeigu operandas nėra loginis, tai jis paverčiamas logine vertė, kad būtų įvertintas. -For instance, the number `1` is treated as `true`, the number `0` as `false`: +Pavyzdžiui, skaičius `1` laikomas `true`, skaičius `0` laikomas `false`: ```js run -if (1 || 0) { // works just like if( true || false ) +if (1 || 0) { // veikia taip pat kaip ( 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`. +Dažniausiai ARBA `||` yra naudojamas `if` teiginiuose, kad pratestuotų ar *kuri nors* iš duotų sąlygų yra `true`. -For example: +Pavyzdžiui: ```js run let hour = 9; @@ -49,91 +49,91 @@ let hour = 9; *!* if (hour < 10 || hour > 18) { */!* - alert( 'The office is closed.' ); + alert( 'Ofisas uždarytas.' ); } ``` -We can pass more conditions: +Galime paleisti ir daugiau sąlygų: ```js run let hour = 12; let isWeekend = true; if (hour < 10 || hour > 18 || isWeekend) { - alert( 'The office is closed.' ); // it is the weekend + alert( 'Ofisas uždarytas.' ); // nes savaitgalis } ``` -## OR "||" finds the first truthy value +## ARBA "||" suranda pirmąją truthy vertę -The logic described above is somewhat classical. Now, let's bring in the "extra" features of JavaScript. +Aukščiau apibūdinta logika yra klasikinė. Dabar pridėkime "ekstra" JavaScript savybių. -The extended algorithm works as follows. +Štai kaip veikia išplėstas algoritmas. -Given multiple OR'ed values: +Turint daugybines ARBA vertes: ```js result = value1 || value2 || value3; ``` -The OR `||` operator does the following: +ARBA `||` operatorius atlieka sekančius veiksmus: -- 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. +- Įvertina operandus iš kairės į dešinę. +- Kiekvieną operandą paverčia į loginę vertę. Jeigu rezultatas yra `true`, sustoja ir grąžina orginalią operando vertę. +- Jeigu visi operandai įvertinti (pvz. visi buvo `false`), grąžinamas paskutinis operandas. -A value is returned in its original form, without the conversion. +Vertė grąžinama savo originalioje formoje be konversijos. -In other words, a chain of OR `"||"` returns the first truthy value or the last one if no truthy value is found. +Kitaip sakant ARBA `"||"` grandinė grąžina pirmąją truthy vertę arba pačią paskutinę vertę, jeigu teisinga vertė nebuvo rasta. -For instance: +Pavyzdžiui: ```js run -alert( 1 || 0 ); // 1 (1 is truthy) -alert( true || 'no matter what' ); // (true is truthy) +alert( 1 || 0 ); // 1 (1 yra truthy) +alert( true || 'nesvarbu kas' ); // (true yra truthy) -alert( null || 1 ); // 1 (1 is the first truthy value) -alert( null || 0 || 1 ); // 1 (the first truthy value) -alert( undefined || null || 0 ); // 0 (all falsy, returns the last value) +alert( null || 1 ); // 1 (1 yra pirmoji truthy vertė) +alert( null || 0 || 1 ); // 1 (pirmoji truthy vertė) +alert( undefined || null || 0 ); // 0 (visos falsy, grąžinama paskutinė vertė) ``` -This leads to some interesting usage compared to a "pure, classical, boolean-only OR". +Tai veda prie labai įdomių panaudojimo būdų, lyginant su "grynu, klasikiniu, loginiu ARBA". -1. **Getting the first truthy value from a list of variables or expressions.** +1. **Gaunant pirmą truthy vertę iš kintamųjų ar išraiškų sąrašo.** - 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? + Įsivaizduokite, kad turime sąrašą kintamųjų, kuriuose arba yra duomenys arba `null/undefined`. Kaip mums surasti pirmąjį su duomenimis? - We can use OR `||`: + Galime naudoti ARBA `||`: ```js run let currentUser = null; let defaultUser = "John"; *!* - let name = currentUser || defaultUser || "unnamed"; + let name = currentUser || defaultUser || "bevardis"; */!* - alert( name ); // selects "John" – the first truthy value + alert( name ); // pasirenka "John" – pirmąją truthy vertę ``` - If both `currentUser` and `defaultUser` were falsy, `"unnamed"` would be the result. -2. **Short-circuit evaluation.** + Jeigu abu `currentUser` ir `defaultUser` būtų falsy, rezultatas būtų `"bevardis"`. +2. **Supaprastintas įvertinimas.** - 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. + Operandai gali būti ne tik vertės, bet ir sutartinės išraiškos. ARBA juos įvertina ir testuoja iš kairės į dešinę. Įvertinimas sustoja kai pasiekiama truthy vertė ir ta vertė sugrąžinama. Toks procesas yra vadinamas "supaprastintu įvertinimu" (ang. "a short-circuit evaluation"), nes jis vyksta taip trumpai iš kairės į dešinę kaip tik įmanoma. - This is clearly seen when the expression given as the second argument has a side effect like a variable assignment. + Tai labai akivaizdu kai išraiška, duota kaip antras argumentas, turi tokį šalutinį efektą kaip kintamojo priskyrimą. - In the example below, `x` does not get assigned: + Pavyzdyje žemiau `x` nėra priskiriamas: ```js run no-beautify let x; *!*true*/!* || (x = 1); - alert(x); // undefined, because (x = 1) not evaluated + alert(x); // undefined, nes (x = 1) nėra įvertinamas ``` - If, instead, the first argument is `false`, `||` evaluates the second one, thus running the assignment: + Tačiau jeigu pirmas argumentas yra `false`, `||` įvertina antrąjį, tada įvykdomas priskyrimas: ```js run no-beautify let x; @@ -143,21 +143,21 @@ This leads to some interesting usage compared to a "pure, classical, boolean-onl alert(x); // 1 ``` - An assignment is a simple case. There may be side effects, that won't show up if the evaluation doesn't reach them. + Asignavimas yra paprastas atvejis. Tam gali būti šalutinių efektų, kurie nepasirodys, jeigu įvertinimas jų nepasieks. - 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. + Kaip matote toks naudojimo atvejis yra "trumpesnis būdas" nei `if`". Pirmasis operandas paverčiamas logine verte, antrasis įvertinamas. - Most of time, it's better to use a "regular" `if` to keep the code easy to understand, but sometimes this can be handy. + Vis dėlto dažniausiai, geriau naudoti "įprastinį" `if`, kad kodas būtų lengviau įskaitomas, bet kartais toks būdas gali būti naudingas. -## && (AND) +## && (IR) -The AND operator is represented with two ampersands `&&`: +IR operatorių atstovauja du ampersandai `&&`: ```js result = a && b; ``` -In classical programming, AND returns `true` if both operands are truthy and `false` otherwise: +Klasikiniame programavime, IR grąžina `true` tik tokiu atveju kai abu operandai yra arba truthy, arba `false`: ```js run alert( true && true ); // true @@ -166,138 +166,138 @@ alert( true && false ); // false alert( false && false ); // false ``` -An example with `if`: +Pavyzdys su `if`: ```js run let hour = 12; let minute = 30; if (hour == 12 && minute == 30) { - alert( 'The time is 12:30' ); + alert( 'Dabar yra 12:30' ); } ``` -Just as with OR, any value is allowed as an operand of AND: +Taip kaip ir su ARBA, bet kokia vertė gali būti IR operandu: ```js run -if (1 && 0) { // evaluated as true && false - alert( "won't work, because the result is falsy" ); +if (1 && 0) { // įvertintas kaip true && false + alert( "neveiks, nes rezultatas yra falsy" ); } ``` -## AND "&&" finds the first falsy value +## IR "&&" suranda pirmą falsy vertę -Given multiple AND'ed values: +Turint daug IR verčių: ```js result = value1 && value2 && value3; ``` -The AND `&&` operator does the following: +Operatorius IR `&&` veikia sekančiai: -- 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. +- Įvertina operandus iš kairės į dešinę. +- Kiekvieną operandą paverčia į loginę vertę. Jeigu rezultatas yra `false`, sustoja ir grąžina originalią operando vertę. +- Jeigu visi operandai buvo įvertinti (pvz. visi buvo truthy), grąžina paskutinį operandą. -In other words, AND returns the first falsy value or the last value if none were found. +Kitais žodžiais IR grąžina pirmą falsy vertę arba jeigu tokių nerado, pačią paskutinę vertę. -The rules above are similar to OR. The difference is that AND returns the first *falsy* value while OR returns the first *truthy* one. +Taisyklės aukščiau yra panašios į ARBA. Skirtumas toks, kad IR grąžina pirmą *falsy* vertę kai tuo tarpu ARBA grąžina pirmą *truthy* vertę. -Examples: +Pavyzdžiai: ```js run -// if the first operand is truthy, -// AND returns the second operand: +// jeigu pirmasis operandas yra truthy, +// IR grąžins antrąjį operandą: alert( 1 && 0 ); // 0 alert( 1 && 5 ); // 5 -// if the first operand is falsy, -// AND returns it. The second operand is ignored +// jeigu pirmasis operandas yra falsy, +// IR jį grąžins. Antrasis operandas ignoruojamas alert( null && 5 ); // null -alert( 0 && "no matter what" ); // 0 +alert( 0 && "nesvarbu kas" ); // 0 ``` -We can also pass several values in a row. See how the first falsy one is returned: +Mes taip pat galime praleisti kelias vertes iš eilės. Atkreipkite dėmesį kaip yra grąžinamas pirmasis falsy: ```js run alert( 1 && 2 && null && 3 ); // null ``` -When all values are truthy, the last value is returned: +Kai visos vertės yra truthy, grąžinama paskutinė vertė: ```js run -alert( 1 && 2 && 3 ); // 3, the last one +alert( 1 && 2 && 3 ); // 3, paskutinis ``` -````smart header="Precedence of AND `&&` is higher than OR `||`" -The precedence of AND `&&` operator is higher than OR `||`. +````smart header="IR `&&` pirmenybė yra aukštesnė už ARBA `||`" +IR `&&` operatoriaus pirmenybė yra aukštesnė už ARBA `||`. -So the code `a && b || c && d` is essentially the same as if the `&&` expressions were in parentheses: `(a && b) || (c && d)`. +Tad kodas `a && b || c && d` būtų tas pats lyg `&&` išraiškos būtų tarp skliaustelių: `(a && b) || (c && d)`. ```` -Just like OR, the AND `&&` operator can sometimes replace `if`. +Taip pat kaip ir ARBA, operatorius IR `&&` kartais gali pakeisti `if`. -For instance: +Pavyzdžiui: ```js run let x = 1; -(x > 0) && alert( 'Greater than zero!' ); +(x > 0) && alert( 'Didesnis nei nulis!' ); ``` -The action in the right part of `&&` would execute only if the evaluation reaches it. That is, only if `(x > 0)` is true. +Veiksmas dešinėje `&&` pusėję įvyktų tik tokiu atveju jeigu įvertinimas jį pasiektų. Tai yra, jeigu `(x > 0)` yra tiesa. -So we basically have an analogue for: +Tad mes tiesiog turime analogą šiai išraiškai: ```js run let x = 1; if (x > 0) { - alert( 'Greater than zero!' ); + alert( 'Didesnis nei nulis!' ); } ``` -The variant with `&&` appears shorter. But `if` is more obvious and tends to be a little bit more readable. +Variantas su `&&` atrodo trumpesnis. Bet `if` yra labiau akivaizdus ir dėl to yra geriau įskaitomas. -So we recommend using every construct for its purpose: use `if` if we want if and use `&&` if we want AND. +Mes rekomenduojame naudoti kiekvieną konstruktą pagal paskirtį: naudokite `if` jeigu norite if, o `&&` jeigu norite IR. -## ! (NOT) +## ! (NE) -The boolean NOT operator is represented with an exclamation sign `!`. +Loginis NE operatorius yra atsotvaujamas šauktuko ženklo `!`. -The syntax is pretty simple: +Sintaksė paprasta: ```js result = !value; ``` -The operator accepts a single argument and does the following: +Operatorius priima vieną argumentą ir atlieka sekančius veiksmus: -1. Converts the operand to boolean type: `true/false`. -2. Returns the inverse value. +1. Konvertuoja operatorių į loginę vertę: `true/false`. +2. Grąžina atvirkštinę vertę. -For instance: +Pavyzdžiui: ```js run alert( !true ); // false alert( !0 ); // true ``` -A double NOT `!!` is sometimes used for converting a value to boolean type: +Dvigubas NE `!!` kartais naudojamas, kad paverstų vertę į loginį tipą: ```js run -alert( !!"non-empty string" ); // true +alert( !!"ne tuščia eilutė" ); // 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. +Tai yra, pirmasis NE paverčia vertę į loginę ir grąžina atvirkštinį variantą, o antrasis NE jį atverčia atgalios. Galų gale turime paprastą konversiją į loginę vertę. -There's a little more verbose way to do the same thing -- a built-in `Boolean` function: +Yra kiek mažiau žodžių reikalaujantis kelias, kuris daro tą patį -- iš anksto paruošta loginė `Boolean` funkcija: ```js run -alert( Boolean("non-empty string") ); // true +alert( Boolean("ne tuščia eilutė") ); // true alert( Boolean(null) ); // false ``` -The precedence of NOT `!` is the highest of all logical operators, so it always executes first, before `&&` or `||`. +Pirmenybė NE `!` yra aukščiausia iš visų loginių operatorių, tad jis visada įvykdomas pirmiau nei `&&` ar `||`.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: