|
1 | | -# Code structure |
| 1 | +# Kodo struktūra |
2 | 2 |
|
3 | | -The first thing we'll study is the building blocks of code. |
| 3 | +Pirmas dalykas, kurį studijuosime yra kodo sudėties blokai. |
4 | 4 |
|
5 | | -## Statements |
| 5 | +## Pareiškimai |
6 | 6 |
|
7 | | -Statements are syntax constructs and commands that perform actions. |
| 7 | +Pareiškimai (ang. Statement) yra sintaksės konstruktai ir komandos, kurios atlieka veiksmus. |
8 | 8 |
|
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!')`, which shows the message "Labas, pasauli!". |
10 | 10 |
|
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. |
12 | 12 |
|
13 | | -For example, here we split "Hello World" into two alerts: |
| 13 | +Pavyzdžiui, čia mes atskirsime "Labas Pasauli" į du perspėjimus: |
14 | 14 |
|
15 | 15 | ```js run no-beautify |
16 | | -alert('Hello'); alert('World'); |
| 16 | +alert('Labas'); alert('Pasauli'); |
17 | 17 | ``` |
18 | 18 |
|
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: |
20 | 20 |
|
21 | 21 | ```js run no-beautify |
22 | | -alert('Hello'); |
23 | | -alert('World'); |
| 22 | +alert('Labas'); |
| 23 | +alert('Pasauli'); |
24 | 24 | ``` |
25 | 25 |
|
26 | | -## Semicolons [#semicolon] |
| 26 | +## Kabliataškiai [#semicolon] |
27 | 27 |
|
28 | | -A semicolon may be omitted in most cases when a line break exists. |
| 28 | +Kabliataškis dažnais atvejais gali būti, pavyzdžiui kai egzistuoja pertrauka eilutėse. |
29 | 29 |
|
30 | | -This would also work: |
| 30 | +Vadinas, tai irgi suveiktų: |
31 | 31 |
|
32 | 32 | ```js run no-beautify |
33 | 33 | alert('Hello') |
34 | 34 | alert('World') |
35 | 35 | ``` |
36 | 36 |
|
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). |
38 | 38 |
|
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"!** |
40 | 40 |
|
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: |
42 | 42 |
|
43 | 43 | ```js run no-beautify |
44 | 44 | alert(3 + |
45 | 45 | 1 |
46 | 46 | + 2); |
47 | 47 | ``` |
48 | 48 |
|
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ų. 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. |
50 | 50 |
|
51 | 51 | **But there are situations where JavaScript "fails" to assume a semicolon where it is really needed.** |
52 | 52 |
|
|
0 commit comments