Skip to content

Commit f48ad01

Browse files
authored
Update article.md
1 parent 5154490 commit f48ad01

File tree

1 file changed

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

1 file changed

+32
-32
lines changed

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

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -99,41 +99,41 @@ alert( undefined || null || 0 ); // 0 (visos falsy, grąžinama paskutinė vert
9999

100100
Tai veda prie labai įdomių panaudojimo būdų, lyginant su "grynu, klasikiniu, loginiu ARBA".
101101

102-
1. **Getting the first truthy value from a list of variables or expressions.**
102+
1. **Gaunant pirmą truthy vertę iš kintamųjų ar išraiškų sąrašo.**
103103

104-
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?
104+
Įsivaizduokite, kad turime sąrašą kintamųjų, kuriuose arba yra duomenys arba `null/undefined`. Kaip mums surasti pirmąjį su duomenimis?
105105

106-
We can use OR `||`:
106+
Galime naudoti ARBA `||`:
107107

108108
```js run
109109
let currentUser = null;
110110
let defaultUser = "John";
111111

112112
*!*
113-
let name = currentUser || defaultUser || "unnamed";
113+
let name = currentUser || defaultUser || "bevardis";
114114
*/!*
115115

116-
alert( name ); // selects "John" – the first truthy value
116+
alert( name ); // pasirenka "John" – pirmąją truthy vertę
117117
```
118118

119-
If both `currentUser` and `defaultUser` were falsy, `"unnamed"` would be the result.
120-
2. **Short-circuit evaluation.**
119+
Jeigu abu `currentUser` ir `defaultUser` būtų falsy, rezultatas būtų `"bevardis"`.
120+
2. **Supaprastintas įvertinimas.**
121121

122-
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.
122+
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.
123123

124-
This is clearly seen when the expression given as the second argument has a side effect like a variable assignment.
124+
Tai labai akivaizdu kai išraiška, duota kaip antras argumentas, turi tokį šalutinį efektą kaip kintamojo priskyrimą.
125125

126-
In the example below, `x` does not get assigned:
126+
Pavyzdyje žemiau `x` nėra priskiriamas:
127127

128128
```js run no-beautify
129129
let x;
130130
131131
*!*true*/!* || (x = 1);
132132
133-
alert(x); // undefined, because (x = 1) not evaluated
133+
alert(x); // undefined, nes (x = 1) nėra įvertinamas
134134
```
135135

136-
If, instead, the first argument is `false`, `||` evaluates the second one, thus running the assignment:
136+
Tačiau jeigu pirmas argumentas yra `false`, `||` įvertina antrąjį, tada įvykdomas priskyrimas:
137137

138138
```js run no-beautify
139139
let x;
@@ -143,21 +143,21 @@ Tai veda prie labai įdomių panaudojimo būdų, lyginant su "grynu, klasikiniu,
143143
alert(x); // 1
144144
```
145145

146-
An assignment is a simple case. There may be side effects, that won't show up if the evaluation doesn't reach them.
146+
Asignavimas yra paprastas atvejis. Tam gali būti šalutinių efektų, kurie nepasirodys, jeigu įvertinimas jų nepasieks.
147147

148-
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.
148+
Kaip matote toks naudojimo atvejis yra "trumpesnis būdas" su `if`". Pirmasis operandas paverčiamas logine verte, antrasis įvertinamas.
149149
150-
Most of time, it's better to use a "regular" `if` to keep the code easy to understand, but sometimes this can be handy.
150+
Dažniausiai, geriau naudoti "įprastinį" `if`, kad kodas būtų lengviau įskaitomas, bet kartais toks būdas gali būti naudingas.
151151
152-
## && (AND)
152+
## && (IR)
153153
154-
The AND operator is represented with two ampersands `&&`:
154+
IR operatorių atstovauja du ampersandai `&&`:
155155
156156
```js
157157
result = a && b;
158158
```
159159
160-
In classical programming, AND returns `true` if both operands are truthy and `false` otherwise:
160+
Klasikiniame programavime, IR grąžina `true` tik tokiu atveju kai abu operandai yra arba truthy, arba `false`:
161161
162162
```js run
163163
alert( true && true ); // true
@@ -166,45 +166,45 @@ alert( true && false ); // false
166166
alert( false && false ); // false
167167
```
168168
169-
An example with `if`:
169+
Pavyzdys su `if`:
170170
171171
```js run
172172
let hour = 12;
173173
let minute = 30;
174174
175175
if (hour == 12 && minute == 30) {
176-
alert( 'The time is 12:30' );
176+
alert( 'Dabar yra 12:30' );
177177
}
178178
```
179179
180-
Just as with OR, any value is allowed as an operand of AND:
180+
Taip kaip ir su ARBA, bet kokia vertė gali būti IR operandu:
181181
182182
```js run
183-
if (1 && 0) { // evaluated as true && false
184-
alert( "won't work, because the result is falsy" );
183+
if (1 && 0) { // įvertintas kaip true && false
184+
alert( "neveiks, nes rezultatas yra falsy" );
185185
}
186186
```
187187
188188
189-
## AND "&&" finds the first falsy value
189+
## IR "&&" suranda pirmą falsy vertę
190190
191-
Given multiple AND'ed values:
191+
Turint daug AND verčių:
192192
193193
```js
194194
result = value1 && value2 && value3;
195195
```
196196
197-
The AND `&&` operator does the following:
197+
Operatorius IR `&&` veikia sekančiai:
198198
199-
- Evaluates operands from left to right.
200-
- For each operand, converts it to a boolean. If the result is `false`, stops and returns the original value of that operand.
201-
- If all operands have been evaluated (i.e. all were truthy), returns the last operand.
199+
- Įvertina operandus iš kairės į dešinę.
200+
- Kiekvieną operandą paverčia į loginę vertę. Jeigu rezultatas yra `false`, sustoja ir grąžina originalią operando vertę.
201+
- Jeigu visi operandai buvo įvertinti (pvz. visi buvo truthy), grąžina paskutinį operandą.
202202
203-
In other words, AND returns the first falsy value or the last value if none were found.
203+
Kitais žodžiais IR grąžina pirmą falsy vertę arba jeigu tokių nerado, pačią paskutinę vertę.
204204
205-
The rules above are similar to OR. The difference is that AND returns the first *falsy* value while OR returns the first *truthy* one.
205+
Taisklė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ę.
206206
207-
Examples:
207+
Pavyzdžiai:
208208
209209
```js run
210210
// if the first operand is truthy,

0 commit comments

Comments
 (0)