Skip to content

Commit 2cc3b71

Browse files
authored
Update article.md
1 parent ebbe5ef commit 2cc3b71

File tree

1 file changed

+76
-76
lines changed

1 file changed

+76
-76
lines changed

1-js/02-first-steps/07-operators/article.md

Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -30,139 +30,139 @@ Prieš tęsiant, išsiaiškinkime įprastinę terminologiją.
3030

3131
## Eilutės sujungimas, binarinis +
3232

33-
Now, let's see special features of JavaScript operators that are beyond school arithmetics.
33+
Dabar susipažinkime su ypatingomis JavaScript savybėmis, kurios pranoksta mokyklos aritmetiką.
3434

35-
Usually, the plus operator `+` sums numbers.
35+
Dažniausiai operatorius pliusas `+` sumuoja skaičius.
3636

37-
But, if the binary `+` is applied to strings, it merges (concatenates) them:
37+
Bet jeigu binarinis `+` pritaikomas eilutėms, pliusas jas sulieja (sujungia):
3838

3939
```js
4040
let s = "my" + "string";
4141
alert(s); // mystring
4242
```
4343

44-
Note that if one of the operands is a string, the other one is converted to a string too.
44+
Atkreipkite dėmesį, jeigu vienas iš operandų yra eilutė, tai kitas taip pat paverčiamas eilute.
4545

46-
For example:
46+
Pavyzdžiui:
4747

4848
```js run
4949
alert( '1' + 2 ); // "12"
5050
alert( 2 + '1' ); // "21"
5151
```
5252

53-
See, it doesn't matter whether the first operand is a string or the second one. The rule is simple: if either operand is a string, the other one is converted into a string as well.
53+
Kaip matote nėra svarbu ar pirmasis operandas ar antrasis yra eilutė. Taisyklė paprasta: jeigu bent vienas operandas yra eilutė, kitas taip pat paverčiamas eilute.
5454

55-
However, note that operations run from left to right. If there are two numbers followed by a string, the numbers will be added before being converted to a string:
55+
Tačiau pastebėkite, kad operacijos vyksta iš kairės į dešinę. Jeigu pirmiau yra du numeriai, kuriuos seka eilutė, numeriai bus susumuoti ir tik tada paversti į eilutę:
5656

5757

5858
```js run
5959
alert(2 + 2 + '1' ); // "41" and not "221"
6060
```
6161

62-
String concatenation and conversion is a special feature of the binary plus `+`. Other arithmetic operators work only with numbers and always convert their operands to numbers.
62+
Eilutės sujungimas ir konversija yra ypatinga binarinio pliuso savybė `+`. Kiti aritmetiniai operatoriai veikia tik su skaičiais ir visada konvertuoja savo operandus į skaičius.
6363

64-
For instance, subtraction and division:
64+
Pavyzdžiui, atimtis ir dalyba:
6565

6666
```js run
6767
alert( 2 - '1' ); // 1
6868
alert( '6' / '2' ); // 3
6969
```
7070

71-
## Numeric conversion, unary +
71+
## Skaitinė konversija, unarinis +
7272

73-
The plus `+` exists in two forms: the binary form that we used above and the unary form.
73+
Pliusas `+` egzistuoja dviejose formose: binarinėje formoje, kurią matėme aukščiau ir unarinėje formoje.
7474

75-
The unary plus or, in other words, the plus operator `+` applied to a single value, doesn't do anything to numbers. But if the operand is not a number, the unary plus converts it into a number.
75+
Unarinis pliusas arba kitaip sumos operatorius `+`, pritaikytas vienetinei vertei, nieko nedaro skaičiams. Bet jeigu operandas nėra skaičius, unarinis pliusas paverčia jį skaičiumi.
7676

77-
For example:
77+
Pavyzdžiui:
7878

7979
```js run
80-
// No effect on numbers
80+
// Jokio efekto skaičiams
8181
let x = 1;
8282
alert( +x ); // 1
8383
8484
let y = -2;
8585
alert( +y ); // -2
8686
8787
*!*
88-
// Converts non-numbers
88+
// Paverčia ne skaičius į skaičius
8989
alert( +true ); // 1
9090
alert( +"" ); // 0
9191
*/!*
9292
```
9393

94-
It actually does the same thing as `Number(...)`, but is shorter.
94+
Tiesą sakant jis daro tą patį kaip `Number(...)`, bet daug trumpesne versija.
9595

96-
The need to convert strings to numbers arises very often. For example, if we are getting values from HTML form fields, they are usually strings. What if we want to sum them?
96+
Poreikis eilutes pakeisti skaičiais pasitaiko labai dažnai. Pavyzdžiui kai gauname vertes iš HTML formų laukelių, jie dažniausiai yra eilutės. Kas jeigu mums reikia jas susumuoti?
9797

98-
The binary plus would add them as strings:
98+
Binarinis pliusas juos sujungtų į eilutę:
9999

100100
```js run
101101
let apples = "2";
102102
let oranges = "3";
103103
104-
alert( apples + oranges ); // "23", the binary plus concatenates strings
104+
alert( apples + oranges ); // "23", binarinis pliusas eilutes sujungia
105105
```
106106

107-
If we want to treat them as numbers, we need to convert and then sum them:
107+
Jeigu mes norime skaičių, pirma turime juos konvertuoti ir tik tada galime susumuoti:
108108

109109
```js run
110110
let apples = "2";
111111
let oranges = "3";
112112
113113
*!*
114-
// both values converted to numbers before the binary plus
114+
// abi vertės iš anksto konvertuojamos į skaičius prieš binarinį pliusą
115115
alert( +apples + +oranges ); // 5
116116
*/!*
117117
118-
// the longer variant
118+
// ilgesnis variantas
119119
// alert( Number(apples) + Number(oranges) ); // 5
120120
```
121121

122-
From a mathematician's standpoint, the abundance of pluses may seem strange. But from a programmer's standpoint, there's nothing special: unary pluses are applied first, they convert strings to numbers, and then the binary plus sums them up.
122+
Iš matematiko perspektyvos gausybė pliusų gali atrodyti keistai. Bet iš programuotojo pozicijos, tai nėra nieko ypatingo: unariniai pliusai pritaikomi pirmi, jie pakeičia eilutes į skaičius, o tada binarinis pliusas juos susumuoja.
123123

124-
Why are unary pluses applied to values before the binary ones? As we're going to see, that's because of their *higher precedence*.
124+
Kodėl unariniai pliusai pritaikomi vertėms pirmiau nei binarinis? Kaip pamatysime vėliau, taip nutinka dėl jų *aukštesnio prioriteto* (ang. *higher precedence*).
125125

126-
## Operator precedence
126+
## Operatorių pirmenybė
127127

128-
If an expression has more than one operator, the execution order is defined by their *precedence*, or, in other words, the default priority order of operators.
128+
Jeigu išraiška turi daugiau operatorių nei vieną, jų vykdymo tvarką yra nustatoma pagal jų *pirmenybę*, arba kitaip sakant, iš ankto numatytąjį operatorių prioritetą.
129129

130-
From school, we all know that the multiplication in the expression `1 + 2 * 2` should be calculated before the addition. That's exactly the precedence thing. The multiplication is said to have *a higher precedence* than the addition.
130+
Dar mokykloje sužinojome, kad daugyba tokioje išraiškoje `1 + 2 * 2` turėtų būti suskaičiuojama prieš sudėtį. Tai ir yra pirmenybė. Yra tariama, kad daugyba turi *aukštesnį prioritetą* negu sudėtis.
131131

132-
Parentheses override any precedence, so if we're not satisfied with the default order, we can use them to change it. For example, write `(1 + 2) * 2`.
132+
Skliausteliai perrašo bet kokią pirmenybę, tad jeigu mums netinka numatyta tvarka, mes galime juos panaudoti, kad tai pakeistume. Pavyzdžiui rašydami `(1 + 2) * 2`.
133133

134-
There are many operators in JavaScript. Every operator has a corresponding precedence number. The one with the larger number executes first. If the precedence is the same, the execution order is from left to right.
134+
JavaScript turi daug operatorių. Kiekvienas operatorius turi atitinkamą pirmenybės numerį. Tas kas turi aukštenį numerį įvykdomas pirmiau. Jeigu prioritetas vienodas, įvykdymo eilė yra iš kairės į dešinę.
135135

136-
Here's an extract from the [precedence table](https://developer.mozilla.org/en/JavaScript/Reference/operators/operator_precedence) (you don't need to remember this, but note that unary operators are higher than corresponding binary ones):
136+
Štai ištrauka iš [pirmenybės lenteltės](https://developer.mozilla.org/en/JavaScript/Reference/operators/operator_precedence) (jums nereikia šito prisiminti, bet žinokite, kad unariniai operatoriai yra aukščiau už atitinkamus binarinius operatorius):
137137

138-
| Precedence | Name | Sign |
138+
| Pirmenybė | Pavadinimas | Ženklas |
139139
|------------|------|------|
140140
| ... | ... | ... |
141-
| 16 | unary plus | `+` |
142-
| 16 | unary negation | `-` |
143-
| 14 | multiplication | `*` |
144-
| 14 | division | `/` |
145-
| 13 | addition | `+` |
146-
| 13 | subtraction | `-` |
141+
| 16 | unarinis pliusas | `+` |
142+
| 16 | unarinis minusas | `-` |
143+
| 14 | daugyba | `*` |
144+
| 14 | dalyba | `/` |
145+
| 13 | sudėtis | `+` |
146+
| 13 | atimtis | `-` |
147147
| ... | ... | ... |
148-
| 3 | assignment | `=` |
148+
| 3 | asignavimas | `=` |
149149
| ... | ... | ... |
150150

151-
As we can see, the "unary plus" has a priority of `16` which is higher than the `13` of "addition" (binary plus). That's why, in the expression `"+apples + +oranges"`, unary pluses work before the addition.
151+
Kaip matome, "unarinis pliusas" turi `16` pirmenybę, kuri yra didesnė nei "sudėties" `13` (binarinis pliusas). Dėl tos priežasties, išraiškoje `"+apples + +oranges"`, unariniai pliusai suveikia pirmiau už sudėtį.
152152

153-
## Assignment
153+
## Asignavimas
154154

155-
Let's note that an assignment `=` is also an operator. It is listed in the precedence table with the very low priority of `3`.
155+
Atkreipkite dėmesį, kad asignavimas (kitaip užduoties operatorius) `=` taip pat yra operatorius. Lentelėje jis įrašytas kaip turintis labai žemą pirmenybę `3`.
156156

157-
That's why, when we assign a variable, like `x = 2 * 2 + 1`, the calculations are done first and then the `=` is evaluated, storing the result in `x`.
157+
Dėl tos priežasties kai mes priskiriame kintamąjį, kaip `x = 2 * 2 + 1`, visų pirma suskaičiuojama vertė ir tik tada `=` yra įvertinamas bei rezultatas patalpinamas į `x`.
158158

159159
```js
160160
let x = 2 * 2 + 1;
161161
162162
alert( x ); // 5
163163
```
164164

165-
It is possible to chain assignments:
165+
Asignavimus įmanoma sujungti į grandinę:
166166

167167
```js run
168168
let a, b, c;
@@ -176,14 +176,14 @@ alert( b ); // 4
176176
alert( c ); // 4
177177
```
178178

179-
Chained assignments evaluate from right to left. First, the rightmost expression `2 + 2` is evaluated and then assigned to the variables on the left: `c`, `b` and `a`. At the end, all the variables share a single value.
179+
Sujungti į grandinę asignavimai įvertinami iš dešinės į kairę. Visų pirmą įvykdoma dešiniausiai esanti išraiška `2 + 2` ir priskiriama kintamiesiems esantiems dešinėje: `c`, `b` ir `a`. Galų gale visi kintamieji dalinasi viena verte.
180180

181-
````smart header="The assignment operator `\"=\"` returns a value"
182-
An operator always returns a value. That's obvious for most of them like addition `+` or multiplication `*`. But the assignment operator follows this rule too.
181+
````smart header="Užduoties operatorius `\"=\"` grąžina vertę"
182+
Operatorius visada grąžina vertę. Tai yra akivaizdu tokiems kaip sudėtis `+` arba daugyba `*`. Bet asignavimas taip pat seka šita taisykle.
183183

184-
The call `x = value` writes the `value` into `x` *and then returns it*.
184+
Šaukimas `x = value` įrašo `value` į `x` *ir tada ją grąžina*.
185185

186-
Here's a demo that uses an assignment as part of a more complex expression:
186+
Štai pavyzdys su asignavimu sudėtingesnėje išraiškoje:
187187

188188
```js run
189189
let a = 1;
@@ -197,79 +197,79 @@ alert( a ); // 3
197197
alert( c ); // 0
198198
```
199199

200-
In the example above, the result of expression `(a = b + 1)` is the value which was assigned to `a` (that is `3`). It is then used for further evaluations.
200+
Pavyzdyje aukščiau, išraiškos `(a = b + 1)` rezultatas yra vertė, kuri buvo priskirta `a` (tai yra `3`). Vėliau ji naudojama tolesniuose vertinimuose.
201201

202-
Funny code, isn't it? We should understand how it works, because sometimes we see it in JavaScript libraries, but shouldn't write anything like that ourselves. Such tricks definitely don't make code clearer or readable.
202+
Kodas yra juokingas, juk taip? Turėtume suprasti kaip jis veikia, nes kartais tokius dalykus randame JavaScript bibliotekose, bet patys tokių geriau nerašykite. Tokie triukai tikrai nepaverčia kodo aiškesniu ir įskaitomesniu.
203203
````
204204

205-
## Remainder %
205+
## Liekana %
206206

207-
The remainder operator `%`, despite its appearance, is not related to percents.
207+
Liekanos operatorius `%`, nepaisant jo išvaizdos, jis nėra susijęs su procentais.
208208

209-
The result of `a % b` is the remainder of the integer division of `a` by `b`.
209+
Šios išraiškos `a % b` rezultatas yra liekana po sveikų skaičių dalybos `a` `b`.
210210

211-
For instance:
211+
Pavyzdžiui:
212212

213213
```js run
214-
alert( 5 % 2 ); // 1 is a remainder of 5 divided by 2
215-
alert( 8 % 3 ); // 2 is a remainder of 8 divided by 3
216-
alert( 6 % 3 ); // 0 is a remainder of 6 divided by 3
214+
alert( 5 % 2 ); // 1 yra liekana kai 5 padalinami iš 2
215+
alert( 8 % 3 ); // 2 yra liekana kai 8 padalinami iš 3
216+
alert( 6 % 3 ); // 0 yra liekana kai 6 padalinami iš 3
217217
```
218218

219-
## Exponentiation **
219+
## Kėlimas laipsniu **
220220

221-
The exponentiation operator `**` is a recent addition to the language.
221+
Kėlimo laipsniu (ang. exponentiation) operatorius `**` yra naujas kalbos priedas.
222222

223-
For a natural number `b`, the result of `a ** b` is `a` multiplied by itself `b` times.
223+
Natūraliajam skaičiui `b`, kai `a ** b` rezultatas yra `a` padaugintas iš savęs `b` kartus.
224224

225-
For instance:
225+
Pavyzdžiui:
226226

227227
```js run
228228
alert( 2 ** 2 ); // 4 (2 * 2)
229229
alert( 2 ** 3 ); // 8 (2 * 2 * 2)
230230
alert( 2 ** 4 ); // 16 (2 * 2 * 2 * 2)
231231
```
232232

233-
The operator works for non-integer numbers as well.
233+
Operatorius veikia ir su trupmenomis.
234234

235-
For instance:
235+
Pavyzdžiui:
236236

237237
```js run
238-
alert( 4 ** (1/2) ); // 2 (power of 1/2 is the same as a square root, that's maths)
239-
alert( 8 ** (1/3) ); // 2 (power of 1/3 is the same as a cubic root)
238+
alert( 4 ** (1/2) ); // 2 (laipsnis 1/2 yra taip pat kaip traukti iš šaknies, tai matematika)
239+
alert( 8 ** (1/3) ); // 2 (laipsnis 1/3 taip pats kaip kubinė šaknis)
240240
```
241241

242-
## Increment/decrement
242+
## Padidėjimas/sumažėjimas
243243

244244
<!-- Can't use -- in title, because built-in parse turns it into – -->
245245
246-
Increasing or decreasing a number by one is among the most common numerical operations.
246+
Skaičiaus padidinimas arba sumažinimas vienetu yra viena dažniausiai naudojamų įprastinių skaičių operacijų.
247247
248-
So, there are special operators for it:
248+
Tad tam netgi yra specialūs operatoriai:
249249
250-
- **Increment** `++` increases a variable by 1:
250+
- **Padidinimas** `++` (ang. increment) kintamąjį padidina 1-u:
251251
252252
```js run no-beautify
253253
let counter = 2;
254-
counter++; // works the same as counter = counter + 1, but is shorter
254+
counter++; // veikia taip pat kaip counter = counter + 1, bet yra trumpesnis
255255
alert( counter ); // 3
256256
```
257-
- **Decrement** `--` decreases a variable by 1:
257+
- **Sumažinimas** `--` (ang. decrement) sumažina kintamajį 1-u:
258258
259259
```js run no-beautify
260260
let counter = 2;
261-
counter--; // works the same as counter = counter - 1, but is shorter
261+
counter--; // veikia taip kaip counter = counter - 1, bet yra trumpesnis
262262
alert( counter ); // 1
263263
```
264264
265265
```warn
266-
Increment/decrement can only be applied to variables. Trying to use it on a value like `5++` will give an error.
266+
Padidinimas/sumažinimas gali būti taikomas tik kintamiesiems. Bandymas jį naudoti vertei kaip pavyzdžiui `5++` sukels klaidą.
267267
```
268268
269-
The operators `++` and `--` can be placed either before or after a variable.
269+
Operatoriai `++` ir `--` gali būti dedami tiek prieš, tiek ir po kintamojo.
270270
271-
- When the operator goes after the variable, it is in "postfix form": `counter++`.
272-
- The "prefix form" is when the operator goes before the variable: `++counter`.
271+
- Kai operatorius eina po kintamojo, jis yra "priedėlio formoje" (ang. "postfix form"): `counter++`.
272+
- "Priešdėlio forma" (ang. "prefix form") yra tada kai operatorius eina prieš kintamąjį: `++counter`.
273273
274274
Both of these statements do the same thing: increase `counter` by `1`.
275275

0 commit comments

Comments
 (0)