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/01-getting-started/1-intro/article.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,9 +24,15 @@ Browser punya engine yang tertanam didalamnya yang disebut "JavaScript virtual m
24
24
25
25
Tiap engine punya *codename*-nya sendiri. Misalnya:
26
26
27
+
<<<<<<< HEAD
27
28
-[V8](https://en.wikipedia.org/wiki/V8_(JavaScript_engine)) -- di Chrome dan Opera.
28
29
-[SpiderMonkey](https://en.wikipedia.org/wiki/SpiderMonkey) -- di Firefox.
29
30
- ...Ada juga codename lain seperti "Trident" dan "Chakra" untuk versi berbeda dari IE, "ChakraCore" untuk Microsoft Edge, "Nitro" dan "SquirrelFish" untuk Safari, dll.
31
+
=======
32
+
-[V8](https://en.wikipedia.org/wiki/V8_(JavaScript_engine)) -- in Chrome and Opera.
33
+
-[SpiderMonkey](https://en.wikipedia.org/wiki/SpiderMonkey) -- in Firefox.
34
+
- ...There are other codenames like "Chakra" for IE, "JavaScriptCore", "Nitro" and "SquirrelFish" for Safari, etc.
35
+
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
30
36
31
37
Istilah di atas sebaiknya diingat karena akan sering digunakan dalam artikel para developer di internet. Kita akan menggunakannya juga. Misalnya, jika "fitur X didukung V8", kemungkinan ia bisa jalan di Chrome dan Opera.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/02-structure/article.md
+33-6Lines changed: 33 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,11 @@ alert(3 +
46
46
+2);
47
47
```
48
48
49
+
<<<<<<< HEAD
49
50
Output dari kode itu adalah `6` karena JavaScript tak menyisipkan titik koma di sini. Sudah jelas sekali bahwa barisnya selesai dengan tanda plus `"+"`, sehingga itu menjadi "expresi tak lengkap", jadi tak butuh titik koma. Dan dalam hal ini memang seperti itu.
51
+
=======
52
+
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 a semicolon there would be incorrect. And in this case, that works as intended.
53
+
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
50
54
51
55
**Tapi ada situasi di mana JavaScript "gagal" mengasumsi titik koma di mana itu benar-benar dibutuhkan.**
52
56
@@ -56,40 +60,63 @@ Galat yang muncul pada kasus ini agak sulit dicari dan dibetulkan.
56
60
Jika kamu penasaran untuk melihat contoh konkrit dari galat ini, cek kode ini:
57
61
58
62
```js run
59
-
[1, 2].forEach(alert)
63
+
alert("Hello");
64
+
65
+
[1, 2].forEach(alert);
60
66
```
61
67
68
+
<<<<<<< HEAD
62
69
Untuk sekarang tak usah memikirkan makna kurung siku `[]` dan `forEach`. Kita akan mempelajari mereka nanti. Untuk sekarang, ingat hasil kode tersebut: yaitu `1` lalu `2`.
63
70
64
71
Sekarang, ayo kita tambahkan `alert` sebelum kodenya *tanpa* diikuti titik koma:
72
+
=======
73
+
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 running the code: it shows `Hello`, then `1`, then `2`.
74
+
75
+
Now let's remove the semicolon after the `alert`:
76
+
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
65
77
66
78
```js run no-beautify
67
-
alert("There will be an error")
79
+
alert("Hello")
68
80
69
-
[1, 2].forEach(alert)
81
+
[1, 2].forEach(alert);
70
82
```
71
83
84
+
<<<<<<< HEAD
72
85
Sekarang jika kita menjalankan kodenya, hanya `alert` pertama yang tampil dan kemudian galat!
73
86
74
87
Tapi semua akan baik-baik saja jika kita menambahkan titik koma setelah `alert`:
75
88
```js run
76
89
alert("All fine now");
90
+
=======
91
+
The difference compared to the code above is only one character: the semicolon at the end of the first line is gone.
92
+
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
77
93
78
-
[1, 2].forEach(alert)
79
-
```
94
+
If we run this code, only the first `Hello` shows (and there's an error, you may need to open the console to see it). There are no numbers any more.
80
95
96
+
<<<<<<< HEAD
81
97
Sekarang kita punya pesan "All fine now" diikuti dengan `1` dan `2`.
82
98
83
99
84
100
Galat muncul pada varian tanpa titik koma karena JavaScript tak mengasumsikan titik koma sebelum kurung siku `[...]`.
85
101
86
102
Jadi, karena titik koma tidak otomatis disisipkan, kode di contoh pertama diperlakukan sebagai pernyataan tunggal. Inilah cara engine melihatnya:
103
+
=======
104
+
That's because JavaScript does not assume a semicolon before square brackets `[...]`. So, the code in the last example is treated as a single statement.
105
+
106
+
Here's how the engine sees it:
107
+
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
87
108
88
109
```js run no-beautify
89
-
alert("There will be an error")[1, 2].forEach(alert)
110
+
alert("Hello")[1, 2].forEach(alert);
90
111
```
91
112
113
+
<<<<<<< HEAD
92
114
Tapi itu harus jadi dua pernyataan terpisah, bukan satu. Penyatuan macam ini salah pada kasus ini, makanya galat. Ini bisa terjadi dalam situasi lain.
115
+
=======
116
+
Looks weird, right? Such merging in this case is just wrong. We need to put a semicolon after `alert` for the code to work correctly.
117
+
118
+
This can happen in other situations also.
119
+
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
93
120
````
94
121
95
122
Kami sarankan menaruh titik koma di antara pernyataan meski mereka dipisahkan garis baru. Ini aturan yang diterima secara luas oleh komunitas. Harap diingat sekali lagi bahwa -- *bisa saja* menanggalkan titik koma di banyak kesempatan. Tapi akan lebih aman -- terutama untuk pemula -- untuk menggunakan mereka.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/05-types/article.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,7 +64,7 @@ Nilai numerik spesial formalnya merupakan bagian dari tipe "number". Tentu saja
64
64
65
65
Kita akan melihat lebih tentang cara bekerja dengan angka di bab <info:number>.
66
66
67
-
## BigInt
67
+
## BigInt [#bigint-type]
68
68
69
69
Didalam Javascript, tipe data "number" tidak bisa mengandung nilai lebih dari <code>(2<sup>53</sup>-1)</code> (sama dengan `9007199254740991`) atau kurang dari <code>-(2<sup>53</sup>-1)</code>. Itu adalah batasan teknik yang dibuat.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/15-function-basics/article.md
+68-4Lines changed: 68 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,10 +20,14 @@ function showMessage() {
20
20
}
21
21
```
22
22
23
+
<<<<<<< HEAD
23
24
Katakunci `fungsi` ditulis duluan, lalu *nama fungsinya*, kemudian daftar semua *parameter* antara tanda kurung () (pada contoh di atas, tanda kurung kosong) dan bagian terakhir adalah fungsi kode, yang juga disebut sebagai "badan fungsi", antara kurung kurawal {}.
25
+
=======
26
+
The `function` keyword goes first, then goes the *name of the function*, then a list of *parameters* between the parentheses (comma-separated, empty in the example above, we'll see examples later) and finally the code of the function, also named "the function body", between curly braces.
Ketika fungsi dipanggil pada penanda `(*)` dan `(**)`, nilai yang diberikan dipindahkan ke variabel lokal `from` dan `text`. Lalu fungsi menggunakan nilai-nilai tersebut.
156
169
157
170
Ini terdapat satu lagi contoh: kita memiliki variabel `from` dan memindahkannya ke fungsi. Dengan catatan: fungsi akan mengubah `from`, tapi perubahan ini tidak akan terlihat di luar fungsi, karena sebuah fungsi akan selalu mendapatkan salinan nilai:
Jika parameter tidak diberi nilai, maka nilainya menjadi `undefined`.
194
+
=======
195
+
When a value is passed as a function parameter, it'salsocalledan*argument*.
196
+
197
+
Inotherwords, toputthesetermsstraight:
198
+
199
+
-Aparameteristhevariablelistedinsidetheparenthesesinthefunctiondeclaration (it's a declaration time term)
200
+
- An argument is the value that is passed to the function when it is called (it'sacalltimeterm).
201
+
202
+
We declare functions listing their parameters, then call them passing arguments.
203
+
204
+
In the example above, one might say: "the function `sayMessage` is declared with two parameters, then called with two arguments: `from` and `"Hello"`".
205
+
206
+
207
+
## Default values
208
+
209
+
If a function is called, but an argument is not provided, then the corresponding value becomes `undefined`.
210
+
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
181
211
182
212
Sebagai gambaran, fungsi yang telah tersebut di atas `showMessage(from, text)` dapat dipanggil dengan argumen tunggal:
183
213
184
214
```js
185
215
showMessage("Ann");
186
216
```
187
217
218
+
<<<<<<< HEAD
188
219
<<<<<<< HEAD
189
220
Itu tidak terjadi kesalahan. Malah pemanggilan tersebut akan menghasilkan `"Ann: undefined"`. Tidak ada argumen untuk parameter `text`, jadi ini diasumsikan bahwa `text === undefined`.
190
221
=======
191
222
That's not an error. Such a call would output `"*Ann*: undefined"`. There's no `text`, so it's assumed that `text === undefined`.
192
223
>>>>>>> f489145731a45df6e369a3c063e52250f3f0061d
193
224
194
225
Jika kita ingin menggunakan suatu `text` "default" pada kasus ini, lalu kita dapat menentukannya setelah `=`:
226
+
=======
227
+
That's not an error. Such a call would output `"*Ann*: undefined"`. As the value for `text` isn't passed, it becomes `undefined`.
228
+
229
+
We can specify the so-called "default" (to use if omitted) value for a parameter in the function declaration, using `=`:
230
+
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
195
231
196
232
```js run
197
233
function showMessage(from, *!*text = "no text given"*/!*) {
@@ -215,19 +251,33 @@ function showMessage(from, text = anotherFunction()) {
Intheexampleabove, `anotherFunction()`isn't called at all, if the `text` parameter is provided.
258
+
259
+
On the other hand, it'sindependentlycalledeverytimewhen`text`ismissing.
260
+
>>>>>>>fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
219
261
```
220
262
221
263
### Alternatif nilai default parameter
222
264
265
+
<<<<<<< HEAD
223
266
Terkadang akan dapat dimengerti untuk memberikan nilai default untuk variabel bukan didalam deklarasi fungsi, tapi di tahap selanjutnya, didalam proses eksekusinya.
224
267
225
268
Untuk memeriksa parameter yang tidak ada, kita bisa membandingkannya dengan `undefined`:
269
+
=======
270
+
Sometimes it makes sense to assign default values for parameters not in the function declaration, but at a later stage.
271
+
272
+
We can check if the parameter is passed during the function execution, by comparing it with `undefined`:
273
+
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
226
274
227
275
```jsrun
228
276
functionshowMessage(text) {
277
+
// ...
278
+
229
279
*!*
230
-
if (text ===undefined) {
280
+
if (text ===undefined) {// if the parameter is missing
231
281
text ='empty message';
232
282
}
233
283
*/!*
@@ -238,21 +288,35 @@ function showMessage(text) {
238
288
showMessage(); // empty message
239
289
```
240
290
291
+
<<<<<<< HEAD
241
292
...Atau kita bisa menggunakan operator `||`:
242
293
243
294
```js
244
295
// jika teks parameter tidak ada atau "", set variabel ke 'empty'
296
+
=======
297
+
...Orwecouldusethe`??`operator:
298
+
299
+
```js
300
+
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
245
301
function showMessage(text) {
302
+
// if text is undefined or otherwise falsy, set it to 'empty'
// jika tidak ada parameter "count", tampilkan "unknown"
313
+
=======
314
+
Modern JavaScript engines support the [nullish coalescing operator](info:nullish-coalescing-operator) `??`, it's better when most falsy values, such as `0`, should be considered "normal":
Copy file name to clipboardExpand all lines: 1-js/04-object-basics/06-constructor-new/article.md
+13-1Lines changed: 13 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,13 +64,21 @@ Sekarang jika kita ingin membuat *user* lain, kita bisa memanggil `new User("Ann
64
64
65
65
Itulah tujuan utama dari konstruktor -- untuk mengimplementasikan kode pembuatan objek yang dapat dipakai ulang (*reusable*).
66
66
67
+
<<<<<<< HEAD
67
68
Mari ingat sekali lagi -- secara teknis, fungsi apapun dapat digunakan sebagai sebuah konstruktor. Hal tersebut berarti: fungsi apapun dapat dijalankan dengan `new`, dan bisa mengeksekusi algoritma di atas. "Huruf kapital dulu" adalah kesepakatan umum, untuk membuatnya lebih jelas bahwa sebuah fungsi untuk dijalankan dengan `new`.
68
69
69
70
````smart header="function() { ... } baru"
70
71
Jika kita memiliki banyak baris kode tentang pembuatan sebuah objek tunggal yang kompleks, kita dapat membungkus kode tersebut dalam fungsi konstruktor, seperti ini:
72
+
=======
73
+
Let's note once again -- technically, any function (except arrow functions, as they don't have `this`) can be used as a constructor. It can be run with `new`, and it will execute the algorithm above. The "capital letter first" is a common agreement, to make it clear that a function is to be run with `new`.
74
+
75
+
````smart header="new function() { ... }"
76
+
If we have many lines of code all about creation of a single complex object, we can wrap them in an immediately called constructor function, like this:
77
+
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
71
78
72
79
```js
73
-
let user = new function() {
80
+
// create a function and immediately call it with new
81
+
let user = new function() {
74
82
this.name = "John";
75
83
this.isAdmin = false;
76
84
@@ -80,7 +88,11 @@ let user = new function() {
80
88
};
81
89
```
82
90
91
+
<<<<<<< HEAD
83
92
Konstruktor tersebut tidak dapat dipanggil lagi, karena tidak disimpan dimanapun, hanya dibuat dan dipanggil. Jadi trik ini ditujukan untuk mengenkapsulasi kode yang mengonstruksi objek tunggal, tanpa penggunaan di masa yang akan datang.
93
+
=======
94
+
This constructor can't be called again, because it is not saved anywhere, just created and called. So this trick aims to encapsulate the code that constructs the single object, without future reuse.
0 commit comments