|
1 | | -# JavaScript specials |
| 1 | +# Особливості JavaScript |
2 | 2 |
|
3 | | -This chapter briefly recaps the features of JavaScript that we've learned by now, paying special attention to subtle moments. |
| 3 | +Давайте коротко повторимо вивчений матеріал і пригадаємо ключові моменти. |
4 | 4 |
|
5 | | -## Code structure |
| 5 | +## Структура коду |
6 | 6 |
|
7 | | -Statements are delimited with a semicolon: |
| 7 | +Інструкції розділяються крапкою з комою: |
8 | 8 |
|
9 | 9 | ```js run no-beautify |
10 | | -alert('Hello'); alert('World'); |
| 10 | +alert('Привіт'); alert('Світ'); |
11 | 11 | ``` |
12 | 12 |
|
13 | | -Usually, a line-break is also treated as a delimiter, so that would also work: |
| 13 | +Зазвичай, перенесення рядка також вважається за розділювач, тому такий варіант теж працюватиме: |
14 | 14 |
|
15 | 15 | ```js run no-beautify |
16 | | -alert('Hello') |
17 | | -alert('World') |
| 16 | +alert('Привіт') |
| 17 | +alert('Світ') |
18 | 18 | ``` |
19 | 19 |
|
20 | | -That's called "automatic semicolon insertion". Sometimes it doesn't work, for instance: |
| 20 | +Це називається "автоматичне вставлення крапки з комою". Іноді такий варіант може не спрацювати, наприклад: |
21 | 21 |
|
22 | 22 | ```js run |
23 | | -alert("There will be an error after this message") |
| 23 | +alert("Після цього повідомлення буде помилка") |
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 | +Більшість посібників по стилю коду рекомендують ставити крапку з комою після кожної інструкції. |
29 | 29 |
|
30 | | -Semicolons are not required after code blocks `{...}` and syntax constructs with them like loops: |
| 30 | +Крапку з комою не потрібно ставити після блоків коду `{...}` та синтаксичних конструкцій з ними, наприклад, після циклів: |
31 | 31 |
|
32 | 32 | ```js |
33 | 33 | function f() { |
34 | | - // no semicolon needed after function declaration |
| 34 | + // після оголошення функції не обов'язково ставити крапку з комою |
35 | 35 | } |
36 | 36 |
|
37 | 37 | for(;;) { |
38 | | - // no semicolon needed after the loop |
| 38 | + // після циклу також немає потреби ставити крапку з комою |
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 | +...Але навіть якщо ми поставимо "зайву" крапку з комою, помилки не буде. Її просто буде проігноровано. |
43 | 43 |
|
44 | | -More in: <info:structure>. |
| 44 | +Детальніше: <info:structure>. |
45 | 45 |
|
46 | 46 | ## Strict mode |
47 | 47 |
|
|
0 commit comments