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
+37-37Lines changed: 37 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,7 @@ if (hour < 10 || hour > 18) {
53
53
}
54
54
```
55
55
56
-
Galime praleisti ir daugiau sąlygų:
56
+
Galime paleisti ir daugiau sąlygų:
57
57
58
58
```js run
59
59
let hour =12;
@@ -145,9 +145,9 @@ Tai veda prie labai įdomių panaudojimo būdų, lyginant su "grynu, klasikiniu,
145
145
146
146
Asignavimas yra paprastas atvejis. Tam gali būti šalutinių efektų, kurie nepasirodys, jeigu įvertinimas jų nepasieks.
147
147
148
-
Kaip matote toks naudojimo atvejis yra "trumpesnis būdas"su`if`". Pirmasis operandas paverčiamas logine verte, antrasis įvertinamas.
148
+
Kaip matote toks naudojimo atvejis yra "trumpesnis būdas"nei`if`". Pirmasis operandas paverčiamas logine verte, antrasis įvertinamas.
149
149
150
-
Dažniausiai, geriau naudoti "įprastinį" `if`, kad kodas būtų lengviau įskaitomas, bet kartais toks būdas gali būti naudingas.
150
+
Vis dėlto dažniausiai, geriau naudoti "įprastinį" `if`, kad kodas būtų lengviau įskaitomas, bet kartais toks būdas gali būti naudingas.
151
151
152
152
## && (IR)
153
153
@@ -188,7 +188,7 @@ if (1 && 0) { // įvertintas kaip true && false
188
188
189
189
## IR "&&" suranda pirmą falsy vertę
190
190
191
-
Turint daug AND verčių:
191
+
Turint daug IR verčių:
192
192
193
193
```js
194
194
result = value1 && value2 && value3;
@@ -202,102 +202,102 @@ Operatorius IR `&&` veikia sekančiai:
202
202
203
203
Kitais žodžiais IR grąžina pirmą falsy vertę arba jeigu tokių nerado, pačią paskutinę vertę.
204
204
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ę.
205
+
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ę.
206
206
207
207
Pavyzdžiai:
208
208
209
209
```js run
210
-
// if the first operand is truthy,
211
-
// AND returns the second operand:
210
+
// jeigu pirmasis operandas yra truthy,
211
+
// IR grąžins antrąjį operandą:
212
212
alert( 1 && 0 ); // 0
213
213
alert( 1 && 5 ); // 5
214
214
215
-
// if the first operand is falsy,
216
-
// AND returns it. The second operand is ignored
215
+
// jeigu pirmasis operandas yra falsy,
216
+
// IR jį grąžins. Antrasis operandas ignoruojamas
217
217
alert( null && 5 ); // null
218
-
alert( 0 && "no matter what" ); // 0
218
+
alert( 0 && "nesvarbu kas" ); // 0
219
219
```
220
220
221
-
We can also pass several values in a row. See how the first falsy one is returned:
221
+
Mes taip pat galime praleisti kelias vertes iš eilės. Atkreipkite dėmesį kaip yra grąžinamas pirmasis falsy:
222
222
223
223
```js run
224
224
alert( 1 && 2 && null && 3 ); // null
225
225
```
226
226
227
-
When all values are truthy, the last value is returned:
227
+
Kai visos vertės yra truthy, grąžinama paskutinė vertė:
228
228
229
229
```js run
230
-
alert( 1 && 2 && 3 ); // 3, the last one
230
+
alert( 1 && 2 && 3 ); // 3, paskutinis
231
231
```
232
232
233
-
````smart header="Precedence ofAND`&&`is higher than OR`||`"
234
-
The precedence of AND `&&` operator is higher than OR `||`.
233
+
````smart header="IR`&&`pirmenybė yra aukštesnė už ARBA`||`"
234
+
IR `&&` operatoriaus pirmenybė yra aukštesnė už ARBA `||`.
235
235
236
-
So the code `a && b || c && d` is essentially the same as if the `&&` expressions were in parentheses: `(a && b) || (c && d)`.
236
+
Tad kodas `a && b || c && d` būtų tas pats lyg `&&` išraiškos būtų tarp skliaustelių: `(a && b) || (c && d)`.
237
237
````
238
238
239
-
Just like OR, the AND `&&` operator can sometimes replace `if`.
239
+
Taip pat kaip ir ARBA, operatorius IR `&&` kartais gali pakeisti `if`.
240
240
241
-
For instance:
241
+
Pavyzdžiui:
242
242
243
243
```js run
244
244
let x = 1;
245
245
246
-
(x > 0) && alert( 'Greater than zero!' );
246
+
(x > 0) && alert( 'Didesnis nei nulis!' );
247
247
```
248
248
249
-
The action in the right part of `&&` would execute only if the evaluation reaches it. That is, only if `(x > 0)` is true.
249
+
Veiksmas dešinėje `&&` pusėję įvyktų tik tokiu atveju jeigu įvertinimas jį pasiektų. Tai yra, jeigu `(x > 0)` yra tiesa.
250
250
251
-
So we basically have an analogue for:
251
+
Tad mes tiesiog turime analogą šiai išraiškai:
252
252
253
253
```js run
254
254
let x = 1;
255
255
256
256
if (x > 0) {
257
-
alert( 'Greater than zero!' );
257
+
alert( 'Didesnis nei nulis!' );
258
258
}
259
259
```
260
260
261
-
The variant with `&&` appears shorter. But `if` is more obvious and tends to be a little bit more readable.
261
+
Variantas su `&&` atrodo trumpesnis. Bet `if` yra labiau akivaizdus ir dėl to yra geriau įskaitomas.
262
262
263
-
So we recommend using every construct for its purpose: use `if` if we want if and use `&&` if we want AND.
263
+
Mes rekomenduojame naudoti kiekvieną konstruktą pagal paskirtį: naudokite `if` jeigu norite if, o `&&` jeigu norite IR.
264
264
265
-
## ! (NOT)
265
+
## ! (NE)
266
266
267
-
The boolean NOT operator is represented with an exclamation sign `!`.
267
+
Loginis NE operatorius yra atsotvaujamas šauktuko ženklo `!`.
268
268
269
-
The syntax is pretty simple:
269
+
Sintaksė paprasta:
270
270
271
271
```js
272
272
result = !value;
273
273
```
274
274
275
-
The operator accepts a single argument and does the following:
275
+
Operatorius priima vieną argumentą ir atlieka sekančius veiksmus:
276
276
277
-
1. Converts the operand to boolean type: `true/false`.
278
-
2. Returns the inverse value.
277
+
1. Konvertuoja operatorių į loginę vertę: `true/false`.
278
+
2. Grąžina atvirkštinę vertę.
279
279
280
-
For instance:
280
+
Pavyzdžiui:
281
281
282
282
```js run
283
283
alert( !true ); // false
284
284
alert( !0 ); // true
285
285
```
286
286
287
-
A double NOT `!!` is sometimes used for converting a value to boolean type:
287
+
Dvigubas NE `!!` kartais naudojamas, kad paverstų vertę į loginį tipą:
288
288
289
289
```js run
290
-
alert( !!"non-empty string" ); // true
290
+
alert( !!"ne tuščia eilutė" ); // true
291
291
alert( !!null ); // false
292
292
```
293
293
294
-
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.
294
+
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ę.
295
295
296
-
There's a little more verbose way to do the same thing -- a built-in `Boolean` function:
296
+
Yra kiek mažiau žodžių reikalaujantis kelias, kuris daro tą patį -- iš anksto paruošta loginė `Boolean` funkcija:
297
297
298
298
```js run
299
-
alert( Boolean("non-empty string") ); // true
299
+
alert( Boolean("ne tuščia eilutė") ); // true
300
300
alert( Boolean(null) ); // false
301
301
```
302
302
303
-
The precedence of NOT `!` is the highest of all logical operators, so it always executes first, before `&&` or `||`.
303
+
Pirmenybė NE `!` yra aukščiausia iš visų loginių operatorių, tad jis visada įvykdomas pirmiau nei `&&` ar `||`.
0 commit comments