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. Matematikos 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 atvejuta 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 vienodo. 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 algorimtas 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
141
There's a non-intuitive behavior when `null` or `undefined` are compared to other values.
0 commit comments