Skip to content

Commit 851187f

Browse files
authored
Merge pull request #109 from javascript-tutorial/temp
Translation of the article "JavaScript specials"
2 parents b81f47d + 8c7bd7f commit 851187f

File tree

1 file changed

+109
-109
lines changed
  • 1-js/02-first-steps/18-javascript-specials

1 file changed

+109
-109
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,184 +1,184 @@
1-
# JavaScript specials
1+
# JavaScript ypatumai
22

3-
This chapter briefly recaps the features of JavaScript that we've learned by now, paying special attention to subtle moments.
3+
Šiame skyriuje trumpai apžvelgiamos iki šiol išmoktos JavaScript savybės, ypatingą dėmesį skiriant subtiliems momentams.
44

5-
## Code structure
5+
## Kodo struktūra
66

7-
Statements are delimited with a semicolon:
7+
Teiginiai atskiriami kabliataškiu:
88

99
```js run no-beautify
10-
alert('Hello'); alert('World');
10+
alert('Labas'); alert('Pasauli');
1111
```
1212

13-
Usually, a line-break is also treated as a delimiter, so that would also work:
13+
Paprastai eilutės laužimas taip pat laikomas skiriamuoju ženklu, todėl jis taip pat tiktų:
1414

1515
```js run no-beautify
1616
alert('Hello')
1717
alert('World')
1818
```
1919

20-
That's called "automatic semicolon insertion". Sometimes it doesn't work, for instance:
20+
Tai vadinama “automatiniu kabliataškio įterpimu”. Kartais tai neveikia, pavyzdžiui:
2121

2222
```js run
23-
alert("There will be an error after this message")
23+
alert("Po šio pranešimo pasirodys klaida")
2424

2525
[1, 2].forEach(alert)
2626
```
2727

28-
Most codestyle guides agree that we should put a semicolon after each statement.
28+
Dauguma kodų stiliaus vadovų sutinka, kad po kiekvieno teiginio turėtume dėti kabliataškį.
2929

30-
Semicolons are not required after code blocks `{...}` and syntax constructs with them like loops:
30+
Po kodo blokų `{...}` ir sintaksės konstrukcijų su jais, pvz., ciklų, kabliataškiai nereikalingi:
3131

3232
```js
3333
function f() {
34-
// no semicolon needed after function declaration
34+
// po funkcijos deklaravimo nereikia kabliataškio
3535
}
3636

3737
for(;;) {
38-
// no semicolon needed after the loop
38+
// po ciklo nereikia kabliataškio
3939
}
4040
```
4141

42-
...But even if we can put an "extra" semicolon somewhere, that's not an error. It will be ignored.
42+
...Tačiau net jei kur nors galime įterpti papildomą kabliataškį, tai nėra klaida. Tai bus ignoruojama.
4343

44-
More in: <info:structure>.
44+
Išsamiau: <info:structure>.
4545

46-
## Strict mode
46+
## Griežtas režimas
4747

48-
To fully enable all features of modern JavaScript, we should start scripts with `"use strict"`.
48+
Kad būtų įjungtos visos šiuolaikinės JavaScript ypatybės, skriptus turėtume pradėti nuo `"use strict"`.
4949

5050
```js
5151
'use strict';
5252

5353
...
5454
```
5555

56-
The directive must be at the top of a script or at the beginning of a function body.
56+
Ši direktyva turi būti skripto viršuje arba funkcijos kūno pradžioje.
5757

58-
Without `"use strict"`, everything still works, but some features behave in the old-fashion, "compatible" way. We'd generally prefer the modern behavior.
58+
Be `"use strict"` viskas veikia, tačiau kai kurios funkcijos veikia senamadiškai, “suderinamumo” būdu. Apskritai mums labiau tiktų šiuolaikinis elgesys.
5959

60-
Some modern features of the language (like classes that we'll study in the future) enable strict mode implicitly.
60+
Kai kurios šiuolaikinės kalbos savybės (pvz., klasės, kurias nagrinėsime ateityje) įgalina griežtąjį režimą netiesiogiai.
6161

62-
More in: <info:strict-mode>.
62+
Išsamiau: <info:strict-mode>.
6363

64-
## Variables
64+
## Kintamieji
6565

66-
Can be declared using:
66+
Galima deklaruoti naudojant:
6767

6868
- `let`
69-
- `const` (constant, can't be changed)
70-
- `var` (old-style, will see later)
69+
- `const` (konstanta, negali būti pakeista)
70+
- `var` (pasenęs būdas, daugiau informacijos vėliau)
7171

72-
A variable name can include:
73-
- Letters and digits, but the first character may not be a digit.
74-
- Characters `$` and `_` are normal, on par with letters.
75-
- Non-Latin alphabets and hieroglyphs are also allowed, but commonly not used.
72+
Kintamojo pavadinimas gali apimti:
73+
- Raidės ir skaitmenys, tačiau pirmasis simbolis negali būti skaitmuo.
74+
- Greta raidžių naudojami simboliai `$` ir `_`.
75+
- Leidžiami ir nelotyniški simboliai bei hieroglifai, tačiau paprastai jie nenaudojami.
7676

77-
Variables are dynamically typed. They can store any value:
77+
Kintamieji yra dinamiškai tipizuojami. Juose galima saugoti bet kokią vertę:
7878

7979
```js
8080
let x = 5;
81-
x = "John";
81+
x = "Jonas";
8282
```
8383

84-
There are 8 data types:
84+
Yra 8 duomenų tipai:
8585

86-
- `number` for both floating-point and integer numbers,
87-
- `bigint` for integer numbers of arbitrary length,
88-
- `string` for strings,
89-
- `boolean` for logical values: `true/false`,
90-
- `null` -- a type with a single value `null`, meaning "empty" or "does not exist",
91-
- `undefined` -- a type with a single value `undefined`, meaning "not assigned",
92-
- `object` and `symbol` -- for complex data structures and unique identifiers, we haven't learnt them yet.
86+
- `number` sveikiesiems ir realiesiems skaičiams,
87+
- `bigint` darbui su savavališkai ilgais sveikaisiais skaičiais,
88+
- `string` eilutėms,
89+
- `boolean` loginėms vertėms: `true/false`,
90+
- `null` -- tipas su vienintele verte `null`, reiškiančia “tuščias” arba “neegzistuoja”,
91+
- `undefined` -- tipas su vienintele verte `undefined`, reiškiančia "nepriskirtas",
92+
- `object` ir `symbol` -- sudėtingoms duomenų struktūroms ir unikaliems identifikatoriams, jų dar nesimokome.
9393

94-
The `typeof` operator returns the type for a value, with two exceptions:
94+
Operatorius `typeof` grąžina vertės tipą, išskyrus dvi išimtis:
9595
```js
96-
typeof null == "object" // error in the language
97-
typeof function(){} == "function" // functions are treated specially
96+
typeof null == "object" // kalbos klaida
97+
typeof function(){} == "function" // funkcijos traktuojamos ypatingai
9898
```
9999

100-
More in: <info:variables> and <info:types>.
100+
Išsamiau: <info:variables> ir <info:types>.
101101

102-
## Interaction
102+
## Interakcija su lankytoju
103103

104-
We're using a browser as a working environment, so basic UI functions will be:
104+
Kaip darbo aplinką naudojame naršyklę, todėl pagrindinės vartotojo sąsajos funkcijos bus:
105105

106106
[`prompt(question, [default])`](mdn:api/Window/prompt)
107-
: Ask a `question`, and return either what the visitor entered or `null` if they clicked "cancel".
107+
: Užduoti klausimą `question` ir grąžinti lankytojo įvestus duomenis arba `null`, jei lankytojas paspaudė “atšaukti”.
108108

109109
[`confirm(question)`](mdn:api/Window/confirm)
110-
: Ask a `question` and suggest to choose between Ok and Cancel. The choice is returned as `true/false`.
110+
: Užduoti klausimą `question` ir pasiūlyti pasirinkti tarp “OK” ir “Atšaukti”. Pasirinkimas grąžinamas kaip `true/false`.
111111

112112
[`alert(message)`](mdn:api/Window/alert)
113-
: Output a `message`.
113+
: Išvesti pranešimą `message`.
114114

115-
All these functions are *modal*, they pause the code execution and prevent the visitor from interacting with the page until they answer.
115+
Visos šios funkcijos yra *modalinės*, jos sustabdo kodo vykdymą ir neleidžia lankytojui sąveikauti su puslapiu, kol jis neatsakys.
116116

117-
For instance:
117+
Pavyzdžiui:
118118

119119
```js run
120-
let userName = prompt("Your name?", "Alice");
121-
let isTeaWanted = confirm("Do you want some tea?");
120+
let userName = prompt("Jūsų vardas?", "Alisa");
121+
let isTeaWanted = confirm("Ar norite arbatos?");
122122

123-
alert( "Visitor: " + userName ); // Alice
124-
alert( "Tea wanted: " + isTeaWanted ); // true
123+
alert( "Lankytojas: " + userName ); // Alisa
124+
alert( "Norėjo arbatos: " + isTeaWanted ); // true
125125
```
126126

127-
More in: <info:alert-prompt-confirm>.
127+
Išsamiau: <info:alert-prompt-confirm>.
128128

129-
## Operators
129+
## Operatoriai
130130

131-
JavaScript supports the following operators:
131+
JavaScript palaiko šiuos operatorius:
132132

133-
Arithmetical
134-
: Regular: `* + - /`, also `%` for the remainder and `**` for power of a number.
133+
Aritmetikos
134+
: Įprasti: `* + - /`, taip pat `%` skirtas dalybos likučiui gauti ir `**` skirtas pakėlimui laipsniu.
135135

136-
The binary plus `+` concatenates strings. And if any of the operands is a string, the other one is converted to string too:
136+
Binarinis pliusas `+` sujungia eilutes. Jei kuris nors iš operandų yra eilutė, kitas operandas taip pat paverčiamas eilute:
137137

138138
```js run
139-
alert( '1' + 2 ); // '12', string
140-
alert( 1 + '2' ); // '12', string
139+
alert( '1' + 2 ); // '12', eilutė
140+
alert( 1 + '2' ); // '12', eilutė
141141
```
142142

143-
Assignments
144-
: There is a simple assignment: `a = b` and combined ones like `a *= 2`.
143+
Priskyrimo operatoriai
144+
: Yra paprastas priskyrimas: `a = b` ir kombinuotas, pavyzdžiui, `a *= 2`.
145145

146-
Bitwise
147-
: Bitwise operators work with 32-bit integers at the lowest, bit-level: see the [docs](mdn:/JavaScript/Guide/Expressions_and_Operators#Bitwise) when they are needed.
146+
Bitų operacijos
147+
: Bitų operatoriai su 32 bitų sveikaisiais skaičiais dirba žemiausiu, bitų lygiu. Daugiau apie jų galite perskaityti [MDN](mdn:/JavaScript/Guide/Expressions_and_Operators#Bitwise).
148148

149-
Conditional
150-
: The only operator with three parameters: `cond ? resultA : resultB`. If `cond` is truthy, returns `resultA`, otherwise `resultB`.
149+
Sąlyginiai operatoriai
150+
: Vienintelis operatorius, turintis tris parametrus: `cond ? resultA : resultB`. Jeigu `cond` yra truthy, grąžina `resultA`, priešingu atveju `resultB`.
151151

152-
Logical operators
153-
: Logical AND `&&` and OR `||` perform short-circuit evaluation and then return the value where it stopped (not necessary `true`/`false`). Logical NOT `!` converts the operand to boolean type and returns the inverse value.
152+
Loginiai operatoriai
153+
: Loginiai IR `&&` ir ARBA `||` atlieka trumpąjį apdorojimą ir grąžina vertę, kurioje jie sustojo (nebūtinai `true`/`false`). Loginis NE `!` konvertuoja operandą į loginį tipą ir grąžina atvirkštinę vertę.
154154

155-
Nullish coalescing operator
156-
: The `??` operator provides a way to choose a defined value from a list of variables. The result of `a ?? b` is `a` unless it's `null/undefined`, then `b`.
155+
Nulinio susiliejimo operatorius.
156+
: Operatorius `??` suteikia galimybę pasirinkti apibrėžtą vertę iš kintamųjų sąrašo. Rezultatas `a ?? b` yra `a`, išskyrus atvejus, kai `a` yra `null/undefined`, tada `b`.
157157

158-
Comparisons
159-
: Equality check `==` for values of different types converts them to a number (except `null` and `undefined` that equal each other and nothing else), so these are equal:
158+
Palyginimas
159+
: Įvairių tipų verčių lygybės patikrinimas `==` paverčia jas skaičiumi (išskyrus `null` ir `undefined`, kurios lygios viena kitai ir niekam kitam), todėl toliau pateikti pavyzdžiai yra lygūs:
160160

161161
```js run
162162
alert( 0 == false ); // true
163163
alert( 0 == '' ); // true
164164
```
165165

166-
Other comparisons convert to a number as well.
166+
Kiti palyginimai taip pat konvertuojami į skaičių.
167167

168-
The strict equality operator `===` doesn't do the conversion: different types always mean different values for it.
168+
Griežtosios lygybės operatorius `===` neatlieka konvertavimo: skirtingi tipai jam visada reiškia skirtingas vertes.
169169

170-
Values `null` and `undefined` are special: they equal `==` each other and don't equal anything else.
170+
Vertės `null` ir `undefined` yra ypatingos: jos lygios `==` viena kitai ir nėra lygios niekam kitam.
171171

172-
Greater/less comparisons compare strings character-by-character, other types are converted to a number.
172+
Daugiau/mažiau palyginimo operatoriai palygina eilutes simbolis po simbolio, kiti tipai konvertuojami į skaičius.
173173

174-
Other operators
175-
: There are few others, like a comma operator.
174+
Kiti operatoriai
175+
: Yra keletas kitų operatorių, pavyzdžiui, kablelio operatorius.
176176

177-
More in: <info:operators>, <info:comparison>, <info:logical-operators>, <info:nullish-coalescing-operator>.
177+
Išsamiau: <info:operators>, <info:comparison>, <info:logical-operators>, <info:nullish-coalescing-operator>.
178178

179-
## Loops
179+
## Ciklai
180180

181-
- We covered 3 types of loops:
181+
- Mes apžvelgėme 3 tipų ciklus:
182182

183183
```js
184184
// 1
@@ -197,43 +197,43 @@ More in: <info:operators>, <info:comparison>, <info:logical-operators>, <info:nu
197197
}
198198
```
199199

200-
- The variable declared in `for(let...)` loop is visible only inside the loop. But we can also omit `let` and reuse an existing variable.
201-
- Directives `break/continue` allow to exit the whole loop/current iteration. Use labels to break nested loops.
200+
- Kintamasis, deklaruotas `for(let...)` cikle, yra matomas tik ciklo viduje. Tačiau taip pat galime praleisti `let` ir pakartotinai panaudoti egzistuojantį kintamąjį.
201+
- Direktyvos `break/continue` leidžia išeiti iš viso ciklo/dabartinės iteracijos. Naudokite žymas norėdami išeiti iš įdėtų ciklų.
202202

203-
Details in: <info:while-for>.
203+
Išsamiau: <info:while-for>.
204204

205-
Later we'll study more types of loops to deal with objects.
205+
Vėliau mes nagrinėsime daugiau ciklų, skirtų darbui su objektais.
206206

207-
## The "switch" construct
207+
## switch” konstrukcija
208208

209-
The "switch" construct can replace multiple `if` checks. It uses `===` (strict equality) for comparisons.
209+
Konstrukcija “switch” gali pakeisti kelis `if` patikrinimus. Palyginimui naudojama `===` (griežta lygybė).
210210

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

213213
```js run
214-
let age = prompt('Your age?', 18);
214+
let age = prompt('Jūsų amžius?', 18);
215215

216216
switch (age) {
217217
case 18:
218-
alert("Won't work"); // the result of prompt is a string, not a number
218+
alert("neveikia"); // prompt rezultatas yra eilutė, o ne skaičius
219219
break;
220220

221221
case "18":
222-
alert("This works!");
222+
alert("Tai veikia!");
223223
break;
224224

225225
default:
226-
alert("Any value not equal to one above");
226+
alert("Bet kuri vertė, nelygi vienai iš aukščiau nurodytų verčių");
227227
}
228228
```
229229

230-
Details in: <info:switch>.
230+
Išsamiau: <info:switch>.
231231

232-
## Functions
232+
## Funkcijos
233233

234-
We covered three ways to create a function in JavaScript:
234+
Mes apžvelgėme tris būdus, kaip galima sukurti funkciją JavaScript:
235235

236-
1. Function Declaration: the function in the main code flow
236+
1. Funkcijos deklaravimas: funkcija pagrindiniame kodo sraute
237237

238238
```js
239239
function sum(a, b) {
@@ -243,7 +243,7 @@ We covered three ways to create a function in JavaScript:
243243
}
244244
```
245245

246-
2. Function Expression: the function in the context of an expression
246+
2. Function Expression: funkcija išraiškos kontekste
247247

248248
```js
249249
let sum = function(a, b) {
@@ -253,32 +253,32 @@ We covered three ways to create a function in JavaScript:
253253
};
254254
```
255255

256-
3. Arrow functions:
256+
3. Rodyklės funkcijos (ang. *“arrow functions*):
257257

258258
```js
259-
// expression at the right side
259+
// išraiška dešinėje pusėje
260260
let sum = (a, b) => a + b;
261261
262-
// or multi-line syntax with { ... }, need return here:
262+
// kelių eilučių kodas figūriniuose skliaustuose { ... }, čia reikalingas return:
263263
let sum = (a, b) => {
264264
// ...
265265
return a + b;
266266
}
267267
268-
// without arguments
268+
// be argumentų
269269
let sayHi = () => alert("Hello");
270270
271-
// with a single argument
271+
// su vienu argumentu
272272
let double = n => n * 2;
273273
```
274274

275275

276-
- Functions may have local variables: those declared inside its body or its parameter list. Such variables are only visible inside the function.
277-
- Parameters can have default values: `function sum(a = 1, b = 2) {...}`.
278-
- Functions always return something. If there's no `return` statement, then the result is `undefined`.
276+
- Funkcijos gali turėti lokalinius kintamuosius: tuos, kurie yra deklaruoti jų viduje arba jų parametrų sąraše. Tokie kintamieji matomi tik funkcijos viduje.
277+
- Parametrai gali turėti numatytąsias vertes: `function sum(a = 1, b = 2) {...}`.
278+
- Funkcijos visada ką nors grąžina. Jei nėra teiginio `return`, rezultatas yra `undefined`.
279279

280-
Details: see <info:function-basics>, <info:arrow-functions-basics>.
280+
Išsamiau: <info:function-basics>, <info:arrow-functions-basics>.
281281

282-
## More to come
282+
## Toliau mes išmoksime daugiau
283283

284-
That was a brief list of JavaScript features. As of now we've studied only basics. Further in the tutorial you'll find more specials and advanced features of JavaScript.
284+
Tai buvo trumpas JavaScript funkcijų sąrašas. Kol kas susipažinome tik su pagrindais. Toliau vadovėlyje jūs rasite daugiau specialiųjų ir išplėstinių JavaScript funkcijų.

0 commit comments

Comments
 (0)