|
1 | | -# JavaScript specials |
| 1 | +# Spesial 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 | +Bab ini secara singkat merekap fitur JavaScript yang sudah kita pelajari sekarang, membayar perhatian khusus ke momen-momen halus. |
4 | 4 |
|
5 | | -## Code structure |
| 5 | +## Struktur kode |
6 | 6 |
|
7 | | -Statements are delimited with a semicolon: |
| 7 | +Pernyataan didelimisi dengan semicolon: |
8 | 8 |
|
9 | 9 | ```js run no-beautify |
10 | 10 | alert('Hello'); alert('World'); |
11 | 11 | ``` |
12 | 12 |
|
13 | | -Usually, a line-break is also treated as a delimiter, so that would also work: |
| 13 | +Biasanya, line-break juga diperlakukan sebagai delimiter, jadi itu juga akan bekerja: |
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 | +Itu disebut "penyisipan semicolon otomatis". Kadang ia tidak bekerja, misalnya: |
21 | 21 |
|
22 | 22 | ```js run |
23 | 23 | alert("There will be an error after this message") |
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 | +Kebanyakan panduan codestyle setuju bahwa kita sebaiknya menaruh semicolon di tiap akhir pernyataan. |
29 | 29 |
|
30 | | -Semicolons are not required after code blocks `{...}` and syntax constructs with them like loops: |
| 30 | +Semicolon tak dibutuhkan setelah blok kode `{...}` dan konstruksi syntax dengan mereka yang seperti loop: |
31 | 31 |
|
32 | 32 | ```js |
33 | 33 | function f() { |
34 | | - // no semicolon needed after function declaration |
| 34 | + // semicolon tak dibutuhkan setelah deklarasi fungsi |
35 | 35 | } |
36 | 36 |
|
37 | 37 | for(;;) { |
38 | | - // no semicolon needed after the loop |
| 38 | + // semicolon tak dibutuhkan setelah loop |
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 | +...Tapi meskipun kita taruh semicolon "extra" di suatu tempat, itu bukan galat. Ia akan diabaikan. |
43 | 43 |
|
44 | | -More in: <info:structure>. |
| 44 | +Lebih lanjut di: <info:structure>. |
45 | 45 |
|
46 | | -## Strict mode |
| 46 | +## Mode ketat |
47 | 47 |
|
48 | | -To fully enable all features of modern JavaScript, we should start scripts with `"use strict"`. |
| 48 | +Untuk mengaktifkan penuh semua fitur modern JavaScript, kita sebaiknya mulai script dengan `"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 | +Directive ini harus ada di paling atas script atau di awal badan fungsi. |
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 | +Tanpa `"use strict"`, apapun akan bekerja, tapi beberapa fitur bersikap dengan cara kuno, "kompatibel". Secara umum kita akan pilih sikap modern. |
59 | 59 |
|
60 | | -Some modern features of the language (like classes that we'll study in the future) enable strict mode implicitly. |
| 60 | +Beberapa fitur modern bahasa ini (seperti kelas yang akan kita pelajari di kemudian) mengaktifkan mode ketat secara implisit. |
61 | 61 |
|
62 | | -More in: <info:strict-mode>. |
| 62 | +Lebih lanjut di: <info:strict-mode>. |
63 | 63 |
|
64 | | -## Variables |
| 64 | +## Variabel |
65 | 65 |
|
66 | 66 | Can be declared using: |
67 | 67 |
|
|
0 commit comments