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
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.
4
4
5
-
## Code structure
5
+
## Kodo struktūra
6
6
7
-
Statements are delimited with a semicolon:
7
+
Teiginiai atskiriami kabliataškiu:
8
8
9
9
```js run no-beautify
10
-
alert('Hello'); alert('World');
10
+
alert('Labas'); alert('Pasauli');
11
11
```
12
12
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ų:
14
14
15
15
```js run no-beautify
16
16
alert('Hello')
17
17
alert('World')
18
18
```
19
19
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:
21
21
22
22
```js run
23
-
alert("There will be an error after this message")
23
+
alert("Po šio pranešimo pasirodys klaida")
24
24
25
25
[1, 2].forEach(alert)
26
26
```
27
27
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į.
29
29
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:
31
31
32
32
```js
33
33
functionf() {
34
-
//no semicolon needed after function declaration
34
+
//po funkcijos deklaravimo nereikia kabliataškio
35
35
}
36
36
37
37
for(;;) {
38
-
//no semicolon needed after the loop
38
+
//po ciklo nereikia kabliataškio
39
39
}
40
40
```
41
41
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.
43
43
44
-
More in: <info:structure>.
44
+
Išsamiau: <info:structure>.
45
45
46
-
## Strict mode
46
+
## Griežtas režimas
47
47
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"`.
49
49
50
50
```js
51
51
'use strict';
52
52
53
53
...
54
54
```
55
55
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.
57
57
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.
59
59
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.
61
61
62
-
More in: <info:strict-mode>.
62
+
Išsamiau: <info:strict-mode>.
63
63
64
-
## Variables
64
+
## Kintamieji
65
65
66
-
Can be declared using:
66
+
Galima deklaruoti naudojant:
67
67
68
68
-`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)
71
71
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.
76
76
77
-
Variables are dynamically typed. They can store any value:
77
+
Kintamieji yra dinamiškai tipizuojami. Juose galima saugoti bet kokią vertę:
78
78
79
79
```js
80
80
let x =5;
81
-
x ="John";
81
+
x ="Jonas";
82
82
```
83
83
84
-
There are 8 data types:
84
+
Yra 8 duomenų tipai:
85
85
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.
93
93
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:
95
95
```js
96
-
typeofnull=="object"//error in the language
97
-
typeoffunction(){} =="function"//functions are treated specially
96
+
typeofnull=="object"//kalbos klaida
97
+
typeoffunction(){} =="function"//funkcijos traktuojamos ypatingai
98
98
```
99
99
100
-
More in: <info:variables>and<info:types>.
100
+
Išsamiau: <info:variables>ir<info:types>.
101
101
102
-
## Interaction
102
+
## Interakcija su lankytoju
103
103
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:
: 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).
148
148
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`.
151
151
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ę.
154
154
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`.
157
157
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:
160
160
161
161
```js run
162
162
alert( 0 == false ); // true
163
163
alert( 0 == '' ); // true
164
164
```
165
165
166
-
Other comparisons convert to a number as well.
166
+
Kiti palyginimai taip pat konvertuojami į skaičių.
167
167
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.
169
169
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.
171
171
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.
173
173
174
-
Other operators
175
-
: There are few others, like a comma operator.
174
+
Kiti operatoriai
175
+
: Yra keletas kitų operatorių, pavyzdžiui, kablelio operatorius.
176
176
177
-
More in: <info:operators>, <info:comparison>, <info:logical-operators>, <info:nullish-coalescing-operator>.
@@ -197,43 +197,43 @@ More in: <info:operators>, <info:comparison>, <info:logical-operators>, <info:nu
197
197
}
198
198
```
199
199
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ų.
202
202
203
-
Details in:<info:while-for>.
203
+
Išsamiau:<info:while-for>.
204
204
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.
206
206
207
-
## The "switch" construct
207
+
## “switch” konstrukcija
208
208
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ė).
210
210
211
-
For instance:
211
+
Pavyzdžiui:
212
212
213
213
```js run
214
-
let age = prompt('Your age?', 18);
214
+
let age = prompt('Jūsų amžius?', 18);
215
215
216
216
switch (age) {
217
217
case18:
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
219
219
break;
220
220
221
221
case"18":
222
-
alert("This works!");
222
+
alert("Tai veikia!");
223
223
break;
224
224
225
225
default:
226
-
alert("Any value not equal to one above");
226
+
alert("Bet kuri vertė, nelygi vienai iš aukščiau nurodytų verčių");
227
227
}
228
228
```
229
229
230
-
Details in: <info:switch>.
230
+
Išsamiau: <info:switch>.
231
231
232
-
## Functions
232
+
## Funkcijos
233
233
234
-
We covered three ways to create a function in JavaScript:
234
+
Mes apžvelgėme tris būdus, kaip galima sukurti funkciją JavaScript:
235
235
236
-
1. Function Declaration: the function in the main code flow
236
+
1.Funkcijos deklaravimas: funkcija pagrindiniame kodo sraute
237
237
238
238
```js
239
239
functionsum(a, b) {
@@ -243,7 +243,7 @@ We covered three ways to create a function in JavaScript:
243
243
}
244
244
```
245
245
246
-
2. Function Expression: the function in the context of an expression
@@ -253,32 +253,32 @@ We covered three ways to create a function in JavaScript:
253
253
};
254
254
```
255
255
256
-
3. Arrow functions:
256
+
3.Rodyklės funkcijos (ang. *“arrow functions”*):
257
257
258
258
```js
259
-
// expression at the right side
259
+
// išraiška dešinėje pusėje
260
260
let sum = (a, b) => a + b;
261
261
262
-
// or multi-line syntax with { ... }, need return here:
262
+
// kelių eilučių kodas figūriniuose skliaustuose { ... }, čia reikalingas return:
263
263
let sum = (a, b) => {
264
264
// ...
265
265
return a + b;
266
266
}
267
267
268
-
// without arguments
268
+
// be argumentų
269
269
let sayHi = () => alert("Hello");
270
270
271
-
// with a single argument
271
+
// su vienu argumentu
272
272
let double = n => n * 2;
273
273
```
274
274
275
275
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`.
279
279
280
-
Details: see <info:function-basics>, <info:arrow-functions-basics>.
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