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
-Greater/less than or equals: <code>a >= b</code>, <code>a <= b</code>.
7
-
-Equals: `a == b` (please note the double equals sign`=`. A single symbol `a = b`would mean an assignment).
8
-
-Not equals. In maths the notation is <code>≠</code>, but in JavaScript it's written as an assignment with an exclamation sign before it: <code>a != b</code>.
-Daugiau/mažiau arba lygu negu: <code>a >= b</code>, <code>a <= b</code>.
7
+
-Lygu: `a == b` (atkreipkite dėmesį į dvigubos lygybės ženklą`=`. Vienas ženklas `a = b`reikštų priskyrimą).
8
+
-Nelygus. Matematikoje toks ženklas yra <code>≠</code>, bet JavaScript jis rašomas kaip asigmentas su šauktuku prieš jį: <code>a != b</code>.
9
9
10
-
## Boolean is the result
10
+
## Loginė vertė yra rezultatas
11
11
12
-
Like all other operators, a comparison returns a value. In this case, the value is a boolean.
12
+
Kaip ir visi kiti operatoriai, palyginimas grąžina vertę. Šiuo atveju ta vertė yra loginė.
13
13
14
-
-`true` -- means "yes", "correct" or "the truth".
15
-
-`false` -- means "no", "wrong" or "not the truth".
14
+
-`true` -- reiškia "taip", "teisingai" arba "tiesa".
15
+
-`false` -- reiškia "ne", "neteisingai" arba "netiesa".
16
16
17
-
For example:
17
+
Pavyzdžiui:
18
18
19
19
```js run
20
-
alert( 2>1 ); // true (correct)
21
-
alert( 2==1 ); // false (wrong)
22
-
alert( 2!=1 ); // true (correct)
20
+
alert( 2>1 ); // true (teisingai)
21
+
alert( 2==1 ); // false (neteisingai)
22
+
alert( 2!=1 ); // true (teisingai)
23
23
```
24
24
25
-
A comparison result can be assigned to a variable, just like any value:
25
+
Palyginimo rezultatas gali būti priskirtas kintamajam, kaip ir bet kuri kita vertė:
26
26
27
27
```js run
28
-
let result =5>4; //assign the result of the comparison
28
+
let result =5>4; //priskirti palyginimo rezultato vertę
29
29
alert( result ); // true
30
30
```
31
31
32
-
## String comparison
32
+
## Eilutės palyginimas
33
33
34
-
To see whether a string is greater than another, JavaScript uses the so-called "dictionary" or "lexicographical" order.
34
+
Kad patikrintų ar viena eilutė yra didesnė už kitą, JavaScript naudoja taip vadinamą "žodyno" arba "leksikografinį" eiliškumą
35
35
36
-
In other words, strings are compared letter-by-letter.
36
+
Kitais žodžiais, eilutės yra lyginamos paraidžiui.
37
37
38
-
For example:
38
+
Pavyzdžiui:
39
39
40
40
```js run
41
41
alert( 'Z'>'A' ); // true
42
42
alert( 'Glow'>'Glee' ); // true
43
43
alert( 'Bee'>'Be' ); // true
44
44
```
45
45
46
-
The algorithm to compare two strings is simple:
46
+
Algoritmas eilučių palyginimui yra labai paprastas:
47
47
48
-
1.Compare the first character of both strings.
49
-
2.If the first character from the first string is greater (or less) than the other string's, then the first string is greater (or less) than the second. We're done.
50
-
3.Otherwise, if both strings' first characters are the same, compare the second characters the same way.
51
-
4.Repeat until the end of either string.
52
-
5.If both strings end at the same length, then they are equal. Otherwise, the longer string is greater.
48
+
1.Palyginti abiejų eilučių pirmus ženklus.
49
+
2.Jeigu pirmas ženklas iš pirmos eilutės yra didesnis (ar mažesnis) negu kitos eilutės, tada pirma eilutė yra didesnė (ar mažesnė) už antrąją. Pabaiga.
50
+
3.Kitu atveju, jeigu abiejų eilučių pirmi ženklai yra vienodi, tada lyginami antri ženklai tuo pačiu principu.
51
+
4.Pakartoti iki vienos iš eilučių pabaigos.
52
+
5.Jeigu abi eilutės baigiasi tuo pačiu metu, jos yra vienodos. Kitu atveju ilgesnė eilutė yra didesnė.
53
53
54
-
In the examples above, the comparison `'Z' > 'A'`gets to a result at the first step while the strings `"Glow"`and`"Glee"`are compared character-by-character:
54
+
Pavyzdyje aukščiau, palyginimas `'Z' > 'A'`gauna atsakymą pirmame žingsnyje, kai tuo tarpu `"Glow"`ir`"Glee"`yra lyginami ženklas po ženklo:
55
55
56
-
1.`G`is the same as`G`.
57
-
2.`l`is the same as`l`.
58
-
3.`o`is greater than`e`. Stop here. The first string is greater.
56
+
1.`G`tas pats kaip`G`.
57
+
2.`l`tas pats kaip`l`.
58
+
3.`o`yra didesnis nei`e`. Čia sustojame. Pirma eilutė yra didesnė.
59
59
60
-
```smart header="Not a real dictionary, but Unicode order"
61
-
The comparison algorithm given above is roughly equivalent to the one used in dictionaries or phone books, but it's not exactly the same.
60
+
```smart header="Ne tikras žodynas, bet Unicode eiliškumas"
61
+
Palyginimo algoritmas esantis aukščiau yra maždaug panašus į tokį koks naudojamas žodynuose ir telefonų knygoje, tačiau jis nėra visiškai toks pats.
62
62
63
-
For instance, case matters. A capital letter `"A"` is not equal to the lowercase `"a"`. Which one is greater? The lowercase `"a"`. Why? Because the lowercase character has a greater index in the internal encoding table JavaScript uses (Unicode). We'll get back to specific details and consequences of this in the chapter <info:string>.
63
+
Pavyzdžiui svarbu ar raidės yra mažosios ar didžiosios. Didžioji raidė `"A"` nėra lygi mažajai raidei `"a"`. Kuri yra didesnė? Mažoji `"a"`. Kodėl? Nes mažosios raidės turi aukštesnį indeksą vidinėje JavaScript kodavimo lentelėje (Unicode). Mes sugrįšime prie specifinių detalių ir pasekmių skyriuje <info:string>.
64
64
```
65
65
66
-
## Comparison of different types
66
+
## Skirtingų tipų palyginimai
67
67
68
-
When comparing values of different types, JavaScript converts the values to numbers.
68
+
JavaScript lygindama skirtingų tipų vertes, jas paverčia į skaičius.
69
69
70
-
For example:
70
+
Pavyzdžiui:
71
71
72
72
```js run
73
-
alert( '2'>1 ); // true, string '2' becomes a number 2
74
-
alert( '01'==1 ); // true, string '01' becomes a number 1
73
+
alert( '2'>1 ); // true, eilutė '2' tampa skaičiumi 2
74
+
alert( '01'==1 ); // true, eilutė '01' tampa skaičiumi 1
75
75
```
76
76
77
-
For boolean values, `true`becomes`1` and`false`becomes`0`.
From JavaScript's standpoint, this result is quite normal. An equality check converts values using the numeric conversion (hence `"0"` becomes `0`), while the explicit `Boolean` conversion uses another set of rules.
104
+
Iš JavaScript pozicijos, toks rezultatas yra visiškai normalus. Palyginimas paverčia vertes naudodamas skaičių konversijas (tad `"0"` tampa `0`), o tuo tarpu išskirtinė loginė `Boolean` konversija naudoja kitokias taisykles.
105
105
````
106
106
107
-
## Strict equality
107
+
## Griežta lygybė
108
108
109
-
A regular equality check `==`has a problem. It cannot differentiate`0`from`false`:
109
+
Įprastinės lygybės patikrinimas `==`turi problemą. Ji negali atskirti`0`nuo`false`:
110
110
111
111
```js run
112
112
alert( 0==false ); // true
113
113
```
114
114
115
-
The same thing happens with an empty string:
115
+
Tas pats nutinka su tuščia eilutė:
116
116
117
117
```js run
118
118
alert( ''==false ); // true
119
119
```
120
120
121
-
This happens because operands of different types are converted to numbers by the equality operator `==`. An empty string, just like `false`, becomes a zero.
121
+
Taip nutinka dėl to, kad skirtingų tipų operandai naudojant lygybės operatorių `==` yra paverčiami į skaičius. Tuščia eilutė, taip pat kaip ir `false`, tampa nuliu.
122
122
123
-
What to do if we'd like to differentiate `0`from`false`?
123
+
Ką daryti jeigu mes norime, kad `0`skirtųsi nuo`false`?
124
124
125
-
**A strict equality operator `===`checks the equality without type conversion.**
125
+
**Griežtos lygybės operatorius `===`patikrina lygybę nedarydamas tipo konversijos.**
126
126
127
-
In other words, if`a`and`b`are of different types, then`a === b`immediately returns `false`without an attempt to convert them.
127
+
Kitaip sakant, jeigu`a`ir`b`yra skirtingų tipų, tada`a === b`iš karto grąžina `false`net nebandydama jų konvertuoti.
128
128
129
-
Let's try it:
129
+
Pabandykime:
130
130
131
131
```js run
132
-
alert( 0===false ); // false, because the types are different
132
+
alert( 0===false ); // false, nes tipai yra skirtingi
133
133
```
134
134
135
-
There is also a "strict non-equality" operator`!==`analogous to`!=`.
135
+
Taip pat yra ir "griežtos nelygybės" operatorius`!==`analogiškas`!=`.
136
136
137
-
The strict equality operator is a bit longer to write, but makes it obvious what's going on and leaves less room for errors.
137
+
Griežtos lygybės operatorius yra ilgesnis, bet jis padeda kodui atrodyti aiškesniu ir palieka mažiau vietos klaidoms.
138
138
139
-
## Comparison with null and undefined
139
+
## Palyginimai su null ir undefined
140
140
141
-
There's a non-intuitive behavior when `null`or`undefined` are compared to other values.
141
+
Kai lyginami`null`ar`undefined`su kitomis vertėmis elgesys nėra intuityvus.
142
142
143
-
For a strict equality check`===`
144
-
: These values are different, because each of them is a different type.
143
+
Griežtos lygybės patikrinime`===`
144
+
: Šios vertės yra skirtingos, nes kiekviena jų yra skirtingo tipo.
145
145
146
146
```js run
147
147
alert( null === undefined ); // false
148
148
```
149
149
150
-
For a non-strict check`==`
151
-
: There's a special rule. These two are a "sweet couple": they equal each other (in the sense of `==`), but not any other value.
150
+
Negriežtos lygybės patikrai`==`
151
+
: Yra speciali taisyklė. Šie du yra "saldi porelė": jie yra lygūs vienas kitam (kai yra `==`), bet jokioms kitoms vertėms.
152
152
153
153
```js run
154
154
alert( null == undefined ); // true
155
155
```
156
156
157
-
For maths and other comparisons`< > <= >=`
158
-
: `null/undefined`are converted to numbers: `null`becomes`0`, while `undefined`becomes`NaN`.
157
+
Matematiniuose ir kitokiuose palyginimuose`< > <= >=`
158
+
: `null/undefined`yra paverčiami skaičiais: `null`tampa`0`, tuo tarpu `undefined`tampa`NaN`.
159
159
160
-
Now let's see some funny things that happen when we apply these rules. And, what's more important, how to not fall into a trap with them.
160
+
Dabar pasižiūrėkime į juokingus atvejus kai šios taisyklės būna pritaikomos. Ir visų svarbiausia kaip dėl jų nepakliūti į spąstus.
161
161
162
-
### Strange result: null vs 0
162
+
### Keistas rezultatas: null vs 0
163
163
164
-
Let's compare `null`with a zero:
164
+
Palyginkime `null`su nuliu:
165
165
166
166
```js run
167
167
alert( null>0 ); // (1) false
168
168
alert( null==0 ); // (2) false
169
169
alert( null>=0 ); // (3) *!*true*/!*
170
170
```
171
171
172
-
Mathematically, that's strange. The last result states that "`null`is greater than or equal to zero", so in one of the comparisons above it must be`true`, but they are both false.
172
+
Tai labai keista matematiškai. Rezultatas sako, kad "`null`yra didesnis arba lygus nuliu", vadinasi viename iš aukščiau esančių palyginimų turėtų būti taip pat`true`, bet jie abu yra neteisingi.
173
173
174
-
The reason is that an equality check`==`and comparisons`> < >= <=`work differently. Comparisons convert`null`to a number, treating it as`0`. That's why (3) `null >= 0`is true and (1) `null > 0`is false.
174
+
To priežastis yra tai, kad lygybės patikrinimas`==`ir palyginimai`> < >= <=`veikia kitaip. Palyginimai paverčia`null`į skaičių ir laiko jį nuliu`0`. Štai dėl ko (3) `null >= 0`yra tiesa, o `null > 0`yra netiesa.
175
175
176
-
On the other hand, the equality check `==`for `undefined`and`null`is defined such that, without any conversions, they equal each other and don't equal anything else. That's why (2) `null == 0`is false.
176
+
Iš kitos pusės, lygybės patikrinimas `==`kaip jau yra apibūdinta, `undefined`ir`null`kai jie nėra konvertuojami, jie yra vienas kitam lygūs, bet nelygūs niekam kitam. Štai kodėl (2) `null == 0`yra netiesa.
177
177
178
-
### An incomparable undefined
178
+
### Nepalyginimasis undefined
179
179
180
-
The value `undefined`shouldn't be compared to other values:
180
+
Vertė `undefined`neturėtų būti lyginima su kitomis vertėmis:
181
181
182
182
```js run
183
183
alert( undefined>0 ); // false (1)
184
184
alert( undefined<0 ); // false (2)
185
185
alert( undefined==0 ); // false (3)
186
186
```
187
187
188
-
Why does it dislike zero so much? Always false!
188
+
Kodėl jis taip nemėgsta nulio? Visada netiesa!
189
189
190
-
We get these results because:
190
+
Gauname tokius rezultatas, nes:
191
191
192
-
-Comparisons`(1)`and`(2)`return`false` because`undefined`gets converted to `NaN` and`NaN`is a special numeric value which returns `false` for all comparisons.
193
-
-The equality check `(3)`returns`false` because`undefined`only equals `null`, `undefined`, and no other value.
192
+
-Palyginimai`(1)`ir`(2)`grąžina`false`, nes`undefined`paverčiamas į `NaN`, o`NaN`yra ypatinga skaitinė vertė, kuri visoms vertėms grąžina `false`.
193
+
-Lygybės patikrinimas `(3)`grąžina`false`, nes`undefined`yra lygus tik `null`, `undefined` ir jokiai kitai vertei.
194
194
195
-
### Evade problems
195
+
### Išvenkite problemų
196
196
197
-
Why did we go over these examples? Should we remember these peculiarities all the time? Well, not really. Actually, these tricky things will gradually become familiar over time, but there's a solid way to evade problems with them:
197
+
Kodėl mes peržiūrėjome tokius pavyzdžius? Ar turėtume tokias keistenybes visada prisiminti? Nebūtinai. Tiesą sakant tokie triukai taps pažįstamais su laiku, bet yra būdas kaip išvengti su jais susijusių problemų:
198
198
199
-
Just treat any comparison with `undefined/null`except the strict equality `===` with exceptional care.
199
+
Kiekvieną palyginimą susijusį su `undefined/null`vertinkite atsargiai, išskyrus su griežta lygybe `===`.
200
200
201
-
Don't use comparisons `>= > < <=`with a variable which may be `null/undefined`, unless you're really sure of what you're doing. If a variable can have these values, check for them separately.
201
+
Nenaudokite palyginimų `>= > < <=`su kintamuoju, kuris gali būti `null/undefined`, nebent tikrai žinote ką darote. Jeigu kintamasis gali turėti tokias vertybes, patikrinkite jas atskirai.
202
202
203
-
## Summary
203
+
## Santrauka
204
204
205
-
-Comparison operators return a boolean value.
206
-
-Strings are compared letter-by-letter in the "dictionary" order.
207
-
-When values of different types are compared, they get converted to numbers (with the exclusion of a strict equality check).
208
-
-The values `null`and`undefined`equal `==`each other and do not equal any other value.
209
-
-Be careful when using comparisons like `>`or`<`with variables that can occasionally be `null/undefined`. Checking for `null/undefined`separately is a good idea.
205
+
-Palyginimų operatoriai grąžina loginę vertę.
206
+
-Eilutės yra tikrinamos paraidžiui "žodynėlio" eiliškumo principu.
207
+
-Kai lyginamos skirtingų tipų vertės, jos yra paverčiamos į skaičius (išskyrus tik griežtą lygybės patikrinimą).
208
+
-Vertės `null`ir`undefined`yra lygios `==`viena kitai, bet nelygios jokiai kitai vertei.
209
+
-Būkite atsargūs kai naudojate tokius palyginimus kaip `>`arba`<`su kintamaisiai, kurie laikas nuo laiko gali būti `null/undefined`. Gera mintis yra patikrinti `null/undefined`atskirai.
0 commit comments