Skip to content

Commit c8acfd9

Browse files
authored
Merge pull request #66 from meilune/master
Second Pull for the structure of code bit
2 parents 1ecf9f3 + 1a8db69 commit c8acfd9

File tree

3 files changed

+68
-68
lines changed

3 files changed

+68
-68
lines changed
+63-63
Original file line numberDiff line numberDiff line change
@@ -1,159 +1,159 @@
1-
# Code structure
1+
# Kodo struktūra
22

3-
The first thing we'll study is the building blocks of code.
3+
Pirmas dalykas, kurį studijuosime yra kodo sudėties blokai.
44

5-
## Statements
5+
## Pareiškimai
66

7-
Statements are syntax constructs and commands that perform actions.
7+
Pareiškimai (ang. Statements) yra sintaksės konstruktai ir komandos, kurios atlieka veiksmus.
88

9-
We've already seen a statement, `alert('Hello, world!')`, which shows the message "Hello, world!".
9+
Mes jau matėme šį pareiškimą, `alert('Labas, pasauli!')`, kuris parodo žinutę "Labas, pasauli!".
1010

11-
We can have as many statements in our code as we want. Statements can be separated with a semicolon.
11+
Mūsų kode gali būti tiek pareiškimų kiek mes norime. Pareiškimai gali būti atskirti kabliataškiu.
1212

13-
For example, here we split "Hello World" into two alerts:
13+
Pavyzdžiui, čia mes atskirsime "Labas Pasauli" į du perspėjimus:
1414

1515
```js run no-beautify
16-
alert('Hello'); alert('World');
16+
alert('Labas'); alert('Pasauli');
1717
```
1818

19-
Usually, statements are written on separate lines to make the code more readable:
19+
Dažniausiai, pareiškimai yra rašomi atskirose eilutėse tam kad kodas būtų lengviau įskaitomas:
2020

2121
```js run no-beautify
22-
alert('Hello');
23-
alert('World');
22+
alert('Labas');
23+
alert('Pasauli');
2424
```
2525

26-
## Semicolons [#semicolon]
26+
## Kabliataškiai [#semicolon]
2727

28-
A semicolon may be omitted in most cases when a line break exists.
28+
Kabliataškis dažnais atvejais gali būti praleidžiamas, kai pavyzdžiui yra pertrauka tarp eilučių.
2929

30-
This would also work:
30+
Tai irgi suveiktų:
3131

3232
```js run no-beautify
3333
alert('Hello')
3434
alert('World')
3535
```
3636

37-
Here, JavaScript interprets the line break as an "implicit" semicolon. This is called an [automatic semicolon insertion](https://tc39.github.io/ecma262/#sec-automatic-semicolon-insertion).
37+
Čia JavaScript interpretuoja pertrauką eilutėse kaip "numanomą" kabliataški. Tai vadinama [automatišku kabliataškio pridėjimu](https://tc39.github.io/ecma262/#sec-automatic-semicolon-insertion).
3838

39-
**In most cases, a newline implies a semicolon. But "in most cases" does not mean "always"!**
39+
**Dažnais atvejais nauja eilutė numanoma kaip kabliataškio pakaitalas. Bet "dažnais atvejais" nereiškia "visada"!**
4040

41-
There are cases when a newline does not mean a semicolon. For example:
41+
Yra tokių atvejų kai nauja eilutė nereiškia kabliataškio. Pavyzdiui:
4242

4343
```js run no-beautify
4444
alert(3 +
4545
1
4646
+ 2);
4747
```
4848

49-
The code outputs `6` because JavaScript does not insert semicolons here. 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.
5050

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.**
5252

53-
Errors which occur in such cases are quite hard to find and fix.
53+
Klaidas tokiais atvejais dažnai sunku surasti ir pataisyti.
5454

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ą:
5757
5858
```js run
5959
[1, 2].forEach(alert)
6060
```
6161
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`.
6363
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:
6565
6666
```js run no-beautify
67-
alert("There will be an error")
67+
alert("Tai bus klaida")
6868
6969
[1, 2].forEach(alert)
7070
```
7171
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ą!
7373
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:
7575
```js run
76-
alert("All fine now");
76+
alert("Dabar viskas gerai");
7777
7878
[1, 2].forEach(alert)
7979
```
8080
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`.
8282
8383
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 `[...]`.
8585
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:
8787
8888
```js run no-beautify
89-
alert("There will be an error")[1, 2].forEach(alert)
89+
alert("Tai bus klaida")[1, 2].forEach(alert)
9090
```
9191
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.
9393
````
9494

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.
9696

97-
## Comments
97+
## Komentarai
9898

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.
100100

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.
102102

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) `//`.**
104104

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ą.
106106

107-
Like here:
107+
Kaip šiuo atveju:
108108
```js run
109-
// This comment occupies a line of its own
110-
alert('Hello');
109+
// Šis komentaras turi savo eilutę
110+
alert('Labas');
111111

112-
alert('World'); // This comment follows the statement
112+
alert('Pasauli'); // Šis komentaras seka paskui pareiškimą
113113
```
114114

115-
**Multiline comments start with a forward slash and an asterisk <code>/&#42;</code> and end with an asterisk and a forward slash <code>&#42;/</code>.**
115+
**Kelių eilučių komentarai prasideda su pasvirusiu brūkšniu ir žvaigždute <code>/&#42;</code> ir pasibaigia žvaigždute ir pasvirusiu brūkšniu <code>&#42;/</code>.**
116116

117-
Like this:
117+
Kaip čia:
118118

119119
```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ų.
122122
*/
123-
alert('Hello');
124-
alert('World');
123+
alert('Labas');
124+
alert('Pasauli');
125125
```
126126

127-
The content of comments is ignored, so if we put code inside <code>/&#42; ... &#42;/</code>, it won't execute.
127+
Komentarų turinys yra ignoruojamas, tad jeigu rašysime kodą tarp <code>/&#42; ... &#42;/</code> jis nebus įvykdytas.
128128

129-
Sometimes it can be handy to temporarily disable a part of code:
129+
Kartais būna naudinga trumpai paslėpti dalį kodo:
130130

131131
```js run
132-
/* Commenting out the code
133-
alert('Hello');
132+
/* Komentaro pagalba paslepiamas kodas
133+
alert('Labas');
134134
*/
135-
alert('World');
135+
alert('Pasauli');
136136
```
137137

138138
```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`.
140140
```
141141

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 `/*...*/`.
144144
145-
Such code will die with an error:
145+
Toks kodas pasibaigs klaida:
146146
147147
```js run no-beautify
148148
/*
149-
/* nested comment ?!? */
149+
/* sudedamasis komentaras ?!? */
150150
*/
151-
alert( 'World' );
151+
alert( 'Pasauli' );
152152
```
153153
````
154154

155-
Please, don't hesitate to comment your code.
155+
Prašau komentuokite savo kodą kaip galima dažniau.
156156

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.
158158

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.

1-js/03-code-quality/01-debugging-chrome/article.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Debugging in Chrome
1+
# Klaidų taisymas naršyklėje Chrome
22

3-
Before writing more complex code, let's talk about debugging.
3+
Prieš rašydami apie sudėtingesnius kodus, pakalbėkime apie klaidų ieškojimą ir taisymą (ang. debugging).
44

5-
[Debugging](https://en.wikipedia.org/wiki/Debugging) is the process of finding and fixing errors within a script. All modern browsers and most other environments support debugging tools -- a special UI in developer tools that makes debugging much easier. It also allows to trace the code step by step to see what exactly is going on.
5+
[Debugging](https://en.wikipedia.org/wiki/Debugging) yra toks procesas kai ieškome ir taisome klaidas skriptuose. Visos modernios naršyklės ir didžioji dalis kitų aplinkų palaiko klaidų taisymo įrankius -- tam tikra programuotojo įrankių vartotojo sąsaja (UI), kuri palengvina klaidų taisymą. Ji taip pat leidžia atsekti kodą žingsnis po žingsnio, kad pamatytume kas iš tikrųjų vyksta.
66

7-
We'll be using Chrome here, because it has enough features, most other browsers have a similar process`.
7+
Mes tam naudosime Chrome, nes jis turi užtektinai funkcijų, bet didžioji dalis naršyklių turi panašius procesus`.
88

99
## The "Sources" panel
1010

1-js/03-code-quality/01-debugging-chrome/debugging.view/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<script src="hello.js"></script>
66

7-
An example for debugging.
7+
Klaidų taisymo pavyzdys.
88

99
<script>
1010
hello("John");

0 commit comments

Comments
 (0)