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
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/02-structure/article.md
+50-50Lines changed: 50 additions & 50 deletions
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,9 @@ Pirmas dalykas, kurį studijuosime yra kodo sudėties blokai.
4
4
5
5
## Pareiškimai
6
6
7
-
Pareiškimai (ang. Statement) yra sintaksės konstruktai ir komandos, kurios atlieka veiksmus.
7
+
Pareiškimai (ang. Statements) yra sintaksės konstruktai ir komandos, kurios atlieka veiksmus.
8
8
9
-
Mes jau matėme šį pareiškimą, `alert('Labas, pasauli!')`, which shows the message "Labas, pasauli!".
9
+
Mes jau matėme šį pareiškimą, `alert('Labas, pasauli!')`, kuris parodo žinutę "Labas, pasauli!".
10
10
11
11
Mūsų kode gali būti tiek pareiškimų kiek mes norime. Pareiškimai gali būti atskirti kabliataškiu.
12
12
@@ -25,9 +25,9 @@ alert('Pasauli');
25
25
26
26
## Kabliataškiai [#semicolon]
27
27
28
-
Kabliataškis dažnais atvejais gali būti, pavyzdžiui kai egzistuoja pertrauka eilutėse.
28
+
Kabliataškis dažnais atvejais gali būti praleidžiamas, kai pavyzdžiui yra pertrauka tarp eilučių.
29
29
30
-
Vadinas, tai irgi suveiktų:
30
+
Tai irgi suveiktų:
31
31
32
32
```js run no-beautify
33
33
alert('Hello')
@@ -46,114 +46,114 @@ alert(3 +
46
46
+2);
47
47
```
48
48
49
-
Kodas mums atiduoda `6`, nes JavaScript šiuo atveju neįterpia kabliataškio tarp eilučių. It is intuitively obvious that if the line ends with a plus `"+"`, then it is an "incomplete expression", so the semicolon is not required. And in this case that works as intended.
49
+
Kodas mums atiduoda `6`, nes JavaScript šiuo atveju neįterpia kabliataškio tarp eilučių. Intuityviai akivaizdu, kad jeigu eilutė pasibaigia pliusu `"+"`, tai yra nepabaigta išraiška (ang. "incomplete expression"), tokiu atveju kabliataškis nereikalingas. O kodas suveikia taip kaip buvo tikėtasi.
50
50
51
-
**But there are situations where JavaScript "fails" to assume a semicolon where it is really needed.**
51
+
**Bet yra situacijų kada JavaScript "nepavyksta" numanyti kabliataškio, kai jo iš tikrųjų reikia.**
52
52
53
-
Errors which occur in such cases are quite hard to find and fix.
53
+
Klaidas tokiais atvejais dažnai sunku surasti ir pataisyti.
54
54
55
-
````smart header="An example of an error"
56
-
If you're curious to see a concrete example of such an error, check this code out:
55
+
````smart header="Klaidos pavyzdys"
56
+
Jeigu jums smalsu pamatyti tokios klaidos konkretų pavyzdį, patikrinkite sekantį kodą:
57
57
58
58
```js run
59
59
[1, 2].forEach(alert)
60
60
```
61
61
62
-
No need to think about the meaning of the brackets `[]` and `forEach` yet. We'll study them later. For now, just remember the result of the code: it shows `1` then `2`.
62
+
Kol kas negalvokite apie šiuos skliaustelius `[]` ir `forEach`. Juos studijuosime vėliau. Jums reikia tik prisiminti kodo rezultatą: jis rodo `1` tada `2`.
63
63
64
-
Now, let's add an `alert` before the code and *not* finish it with a semicolon:
64
+
O dabar pridėkime `alert` prieš kodą ir *neužbaikime* jo su kabliataškiu:
65
65
66
66
```js run no-beautify
67
-
alert("There will be an error")
67
+
alert("Tai bus klaida")
68
68
69
69
[1, 2].forEach(alert)
70
70
```
71
71
72
-
Now if we run the code, only the first `alert` is shown and then we have an error!
72
+
Dabar jeigu paleisime šį kodą, tik pirmasis `alert` pasirodo, o tada gauname klaidą!
73
73
74
-
But everything is fine again if we add a semicolon after `alert`:
74
+
Bet jeigu pridedame kabliataškį po `alert` vėl viskas gerai:
75
75
```js run
76
-
alert("All fine now");
76
+
alert("Dabar viskas gerai");
77
77
78
78
[1, 2].forEach(alert)
79
79
```
80
80
81
-
Now we have the "All fine now" message followed by `1` and `2`.
81
+
Gauname "Dabar viskas gerai" žinutę, kurią seka `1` ir `2`.
82
82
83
83
84
-
The error in the no-semicolon variant occurs because JavaScript does not assume a semicolon before square brackets `[...]`.
84
+
Klaida variante be kabliataškio atsiranda dėl to, kad JavaScript nenumato galimo kabliataškio prieš laužtinius skliaustelius `[...]`.
85
85
86
-
So, because the semicolon is not auto-inserted, the code in the first example is treated as a single statement. Here's how the engine sees it:
86
+
Kadangi kabliataškis nėra automatiškai įtraukiamas, pirmojo pavyzdžio kodas laikomas vienu pilnu pareiškimu. Štai kaip jį mato sistema:
87
87
88
88
```js run no-beautify
89
-
alert("There will be an error")[1, 2].forEach(alert)
89
+
alert("Tai bus klaida")[1, 2].forEach(alert)
90
90
```
91
91
92
-
But it should be two separate statements, not one. Such a merging in this case is just wrong, hence the error. This can happen in other situations.
92
+
Bet tai turėtų būti du atskiri pareiškimai, ne vienas. Toks sujungimas šiuo atveju yra neteisingas, dėl to ir gauname klaidą. Taip gali nutikti ir kitose situacijose.
93
93
````
94
94
95
-
We recommend putting semicolons between statements even if they are separated by newlines. This rule is widely adopted by the community. Let's note once again -- *it is possible* to leave out semicolons most of the time. But it's safer -- especially for a beginner -- to use them.
95
+
Mes rekomenduojame dėti kabliataškius pareiškimų pabaigoje net jeigu jie yra atskirose eilutėse. Tokia taisyklė yra plačiai naudojama. Dar kartą prisiminkime -- *įmanoma* daugeliu atvejų kabliataškių nedėti. Bet daug saugiau -- ypač naujokams -- juos naudoti.
96
96
97
-
## Comments
97
+
## Komentarai
98
98
99
-
As time goes on, programs become more and more complex. It becomes necessary to add *comments* which describe what the code does and why.
99
+
Laikui bėgant programos tampa vis sudėtingesnės, dėl to svarbu pridėti komentarus (ang. *comments*), kurie paaiškintų ką kodas daro ir kodėl.
100
100
101
-
Comments can be put into any place of a script. They don't affect its execution because the engine simply ignores them.
101
+
Komentarus galima dėti bet kurioje skriptų vietoje. Jie nedaro įtakos kodo atlikimui, nes sistema juos paprasčiausiai ignoruoja.
102
102
103
-
**One-line comments start with two forward slash characters`//`.**
103
+
**Vienos eilutės komentarai prasideda su dviem į priekį pasvirusiais brūkšniais (ang. forward slashes)`//`.**
104
104
105
-
The rest of the line is a comment. It may occupy a full line of its own or follow a statement.
105
+
Likusi eilutės dalis yra komentaras. Jis gali užimti pilną eilutę arba užbaigti pareiškimą.
106
106
107
-
Like here:
107
+
Kaip šiuo atveju:
108
108
```js run
109
-
//This comment occupies a line of its own
110
-
alert('Hello');
109
+
//Šis komentaras turi savo eilutę
110
+
alert('Labas');
111
111
112
-
alert('World'); //This comment follows the statement
112
+
alert('Pasauli'); //Šis komentaras seka paskui pareiškimą
113
113
```
114
114
115
-
**Multiline comments start with a forward slash and an asterisk <code>/*</code> and end with an asterisk and a forward slash <code>*/</code>.**
115
+
**Kelių eilučių komentarai prasideda su pasvirusiu brūkšniu ir žvaigždute <code>/*</code> ir pasibaigia žvaigždute ir pasvirusiu brūkšniu <code>*/</code>.**
116
116
117
-
Like this:
117
+
Kaip čia:
118
118
119
119
```js run
120
-
/*An example with two messages.
121
-
This is a multiline comment.
120
+
/*Pavyzdys su dviem žinutėmis.
121
+
Šis komentaras gali būti kelių eilučių.
122
122
*/
123
-
alert('Hello');
124
-
alert('World');
123
+
alert('Labas');
124
+
alert('Pasauli');
125
125
```
126
126
127
-
The content of comments is ignored, so if we put code inside <code>/* ... */</code>, it won't execute.
127
+
Komentarų turinys yra ignoruojamas, tad jeigu rašysime kodą tarp <code>/* ... */</code> jis nebus įvykdytas.
128
128
129
-
Sometimes it can be handy to temporarily disable a part of code:
129
+
Kartais būna naudinga trumpai paslėpti dalį kodo:
130
130
131
131
```js run
132
-
/*Commenting out the code
133
-
alert('Hello');
132
+
/*Komentaro pagalba paslepiamas kodas
133
+
alert('Labas');
134
134
*/
135
-
alert('World');
135
+
alert('Pasauli');
136
136
```
137
137
138
138
```smart header="Use hotkeys!"
139
-
In most editors, a line of code can be commented out by pressing the `key:Ctrl+/` hotkey for a single-line comment and something like `key:Ctrl+Shift+/` -- for multiline comments (select a piece of code and press the hotkey). For Mac, try `key:Cmd` instead of `key:Ctrl`.
139
+
Didžiojoje dalyje redaktorių vieno kodo eilutė gali būti paversta komentaru spaudžiant klaviatūroje vienu metu `key:Ctrl+/`, o kelių eilučių komentaras gaunamas spaudžiant `key:Ctrl+Shift+/` -- (išbandykite tai patys su savo kodu). Mac kompiuteriuose, naudokite `key:Cmd` vietoje `key:Ctrl`.
140
140
```
141
141
142
-
````warn header="Nested comments are not supported!"
143
-
There may not be `/*...*/` inside another `/*...*/`.
142
+
````warn header="Sudedamieji (ang. nested) komentarai nėra galimi!"
143
+
Negali būti dar vieno `/*...*/` kitame `/*...*/`.
144
144
145
-
Such code will die with an error:
145
+
Toks kodas pasibaigs klaida:
146
146
147
147
```js run no-beautify
148
148
/*
149
-
/* nested comment ?!? */
149
+
/* sudedamasis komentaras ?!? */
150
150
*/
151
-
alert( 'World' );
151
+
alert( 'Pasauli' );
152
152
```
153
153
````
154
154
155
-
Please, don't hesitate to comment your code.
155
+
Prašau komentuokite savo kodą kaip galima dažniau.
156
156
157
-
Comments increase the overall code footprint, but that's not a problem at all. There are many tools which minify code before publishing to a production server. They remove comments, so they don't appear in the working scripts. Therefore, comments do not have negative effects on production at all.
157
+
Komentarai išplečia kodo užimamą vietą, tačiau tai nėra problema. Yra pakankamai įrankių, kurie sumažina kodą prieš jį paleisdami į serverius. Jie panaikina komentarus, kad jie nesimatytų dirbančiame kode, tad komentarai neturi neigiamo efekto produkcijai.
158
158
159
-
Later in the tutorial there will be a chapter <info:code-quality> that also explains how to write better comments.
159
+
Vėliau pamokose bus skyrius apie kodo kokybę <info:code-quality>, kur taip pat paaiškinama kaip rašyti geresnius komentarus.
0 commit comments