Skip to content

Commit 5154490

Browse files
authored
Update article.md
1 parent 5c81a53 commit 5154490

File tree

1 file changed

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

1 file changed

+34
-34
lines changed

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

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
# Logical operators
1+
# Loginiai operatoriai
22

3-
There are three logical operators in JavaScript: `||` (OR), `&&` (AND), `!` (NOT).
3+
JavaScript yra trys loginiai operatoriai: `||` (OR - arba), `&&` (AND - ir), `!` (NOT - ne).
44

5-
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.
5+
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.
66

7-
Let's see the details.
7+
Pažiūrėkime detaliau.
88

99
## || (OR)
1010

11-
The "OR" operator is represented with two vertical line symbols:
11+
Dvi vertikalios linijos atstoja "ARBA" operatorių:
1212

1313
```js
1414
result = a || b;
1515
```
1616

17-
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`.
17+
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`.
1818

19-
In JavaScript, the operator is a little bit trickier and more powerful. But first, let's see what happens with boolean values.
19+
JavaScript operatorius yra šiek tiek sudėtingesnis ir galingesnis. Bet visų pirma pažvelkime kas nutinka su loginėmis vertėmis.
2020

21-
There are four possible logical combinations:
21+
Yra keturios įmanomos loginės kombinacijos:
2222

2323
```js run
2424
alert( true || true ); // true
@@ -27,77 +27,77 @@ alert( true || false ); // true
2727
alert( false || false ); // false
2828
```
2929

30-
As we can see, the result is always `true` except for the case when both operands are `false`.
30+
Kaip matome, rezultatas yra visada `true` išskyrus kai abu operandai yra `false`.
3131

32-
If an operand is not a boolean, it's converted to a boolean for the evaluation.
32+
Jeigu operandas nėra loginis, tai jis paverčiamas logine vertė, kad būtų įvertintas.
3333

34-
For instance, the number `1` is treated as `true`, the number `0` as `false`:
34+
Pavyzdžiui, skaičius `1` laikomas `true`, skaičius `0` laikomas `false`:
3535

3636
```js run
37-
if (1 || 0) { // works just like if( true || false )
37+
if (1 || 0) { // veikia taip pat kaip ( true || false )
3838
alert( 'truthy!' );
3939
}
4040
```
4141

42-
Most of the time, OR `||` is used in an `if` statement to test if *any* of the given conditions is `true`.
42+
Dažniausiai ARBA `||` yra naudojamas `if` teiginiuose, kad pratestuotų ar *kuri nors* iš duotų sąlygų yra `true`.
4343

44-
For example:
44+
Pavyzdžiui:
4545

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

4949
*!*
5050
if (hour < 10 || hour > 18) {
5151
*/!*
52-
alert( 'The office is closed.' );
52+
alert( 'Ofisas uždarytas.' );
5353
}
5454
```
5555

56-
We can pass more conditions:
56+
Galime praleisti ir daugiau sąlygų:
5757

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

6262
if (hour < 10 || hour > 18 || isWeekend) {
63-
alert( 'The office is closed.' ); // it is the weekend
63+
alert( 'Ofisas uždarytas.' ); // nes savaitgalis
6464
}
6565
```
6666

67-
## OR "||" finds the first truthy value
67+
## ARBA "||" suranda pirmąją truthy vertę
6868

69-
The logic described above is somewhat classical. Now, let's bring in the "extra" features of JavaScript.
69+
Aukščiau apibūdinta logika yra klasikinė. Dabar pridėkime "ekstra" JavaScript savybių.
7070

71-
The extended algorithm works as follows.
71+
Štai kaip veikia išplėstas algoritmas.
7272

73-
Given multiple OR'ed values:
73+
Turint daugybines ARBA vertes:
7474

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

79-
The OR `||` operator does the following:
79+
ARBA `||` operatorius atlieka sekančius veiksmus:
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+
- Įvertina operandus iš kairės į dešinę.
82+
- Kiekvieną operandą paverčia į loginę vertę. Jeigu rezultatas yra `true`, sustoja ir grąžina orginalią operando vertę.
83+
- Jeigu visi operandai įvertinti (pvz. visi buvo `false`), grąžinamas paskutinis operandas.
8484

85-
A value is returned in its original form, without the conversion.
85+
Vertė grąžinama savo originalioje formoje be konversijos.
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+
Kitaip sakant ARBA `"||"` grandinė grąžina pirmąją truthy vertę arba pačią paskutinę vertę, jeigu teisinga vertė nebuvo rasta.
8888

89-
For instance:
89+
Pavyzdžiui:
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 yra truthy)
93+
alert( true || 'nesvarbu kas' ); // (true yra truthy)
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 yra pirmoji truthy vertė)
96+
alert( null || 0 || 1 ); // 1 (pirmoji truthy vertė)
97+
alert( undefined || null || 0 ); // 0 (visos falsy, grąžinama paskutinė vertė)
9898
```
9999

100-
This leads to some interesting usage compared to a "pure, classical, boolean-only OR".
100+
Tai veda prie labai įdomių panaudojimo būdų, lyginant su "grynu, klasikiniu, loginiu ARBA".
101101

102102
1. **Getting the first truthy value from a list of variables or expressions.**
103103

0 commit comments

Comments
 (0)