Skip to content

Commit 81a36a0

Browse files
committed
merging all conflicts
2 parents 06970e5 + 4d01fc2 commit 81a36a0

File tree

36 files changed

+628
-67
lines changed

36 files changed

+628
-67
lines changed

1-js/02-first-steps/04-variables/article.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ Kini, kita bisa menaruh beberapa data ke dalamnya dengan menggunakan operator pe
2424
let message;
2525

2626
*!*
27+
<<<<<<< HEAD
2728
message = 'Hello'; // simpan string
29+
=======
30+
message = 'Hello'; // store the string 'Hello' in the variable named message
31+
>>>>>>> 4d01fc20d4d82358e61518a31efe80dec9bb2602
2832
*/!*
2933
```
3034

1-js/02-first-steps/13-while-for/article.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,17 @@ Mari bahas pernyataan `for` bagian demi bagian:
106106

107107
| bagian | | |
108108
|-------|----------|----------------------------------------------------------------------------|
109+
<<<<<<< HEAD
109110
| begin | `i = 0` | Jalankan sekali masuk ke loop. |
110111
| condition | `i < 3`| Cek sebelum tiap iterasi loop. Jika salah, loop berhenti. |
111112
| body | `alert(i)`| Jalankan lagi dan lagi selama kondisi bernilai truthy. |
112113
| step | `i++` | Exekusi setelah badan di tiap iterasi. |
114+
=======
115+
| begin | `let i = 0` | Executes once upon entering the loop. |
116+
| condition | `i < 3`| Checked before every loop iteration. If false, the loop stops. |
117+
| body | `alert(i)`| Runs again and again while the condition is truthy. |
118+
| step| `i++` | Executes after the body on each iteration. |
119+
>>>>>>> 4d01fc20d4d82358e61518a31efe80dec9bb2602
113120
114121
Cara kerja algoritma perulangan umum seperti ini:
115122

@@ -377,7 +384,11 @@ label: {
377384
}
378385
```
379386
387+
<<<<<<< HEAD
380388
...Meskipun, 99,9% dari waktu `break` yang digunakan adalah loop dalam, seperti yang telah kita lihat pada contoh di atas.
389+
=======
390+
...Although, 99.9% of the time `break` is used inside loops, as we've seen in the examples above.
391+
>>>>>>> 4d01fc20d4d82358e61518a31efe80dec9bb2602
381392
382393
`continue` hanya dimungkinkan dari dalam loop.
383394
````

1-js/02-first-steps/15-function-basics/article.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ Dengan kata lain, untuk meluruskan istilah-istilah ini:
181181
- Parameter adalah variabel yang tercantum di dalam tanda kurung dalam deklarasi fungsi (ini adalah istilah waktu deklarasi)
182182
- Argumen adalah nilai yang diteruskan ke fungsi saat dipanggil (ini adalah istilah waktu panggilan).
183183
184+
<<<<<<< HEAD
184185
Kami mendeklarasikan fungsi yang mencantumkan parameternya, lalu memanggilnya lewat argumen.
186+
=======
187+
In the example above, one might say: "the function `showMessage` is declared with two parameters, then called with two arguments: `from` and `"Hello"`".
188+
>>>>>>> 4d01fc20d4d82358e61518a31efe80dec9bb2602
185189
186190
Dalam contoh di atas, seseorang mungkin mengatakan: "fungsi `sayMessage` dideklarasikan dengan dua parameter, kemudian dipanggil dengan dua argumen: `from` dan `"Hello"`".
187191
@@ -250,7 +254,11 @@ function showMessage(text) {
250254
showMessage(); // empty message
251255
```
252256
257+
<<<<<<< HEAD
253258
...Atau kita bisa menggunakan operator `||`:
259+
=======
260+
...Or we could use the `||` operator:
261+
>>>>>>> 4d01fc20d4d82358e61518a31efe80dec9bb2602
254262
255263
```js
256264
// jika teks parameter tidak ada atau "", set variabel ke 'empty'

1-js/03-code-quality/06-polyfills/article.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ di chapter ini, tujuan kita adalah untuk mendapatkan intisari cara kerjanya, dan
2121

2222
## Transpilers
2323

24+
<<<<<<< HEAD
2425
Sebuah [transpiler](https://en.wikipedia.org/wiki/Source-to-source_compiler) adalah perangkat lunak khusus yang dapat mengurai ("membaca dan memahami") kode modern, dan menulis ulang menggunakan konstruksi sintaks yang lebih lama, sehingga hasilnya akan sama.
26+
=======
27+
A [transpiler](https://en.wikipedia.org/wiki/Source-to-source_compiler) is a special piece of software that translates source code to another source code. It can parse ("read and understand") modern code and rewrite it using older syntax constructs, so that it'll also work in outdated engines.
28+
>>>>>>> 4d01fc20d4d82358e61518a31efe80dec9bb2602
2529
2630
Misalnya. JavaScript sebelum tahun 2020 tidak memiliki "nullish coalescing operator" `??`. Jadi, jika pengunjung menggunakan browser yang sudah ketinggalan zaman, ia mungkin gagal memahami kode seperti `height = height ?? 100`
2731

1-js/04-object-basics/06-constructor-new/1-two-functions-one-object/task.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ importance: 2
44

55
# Dua fungsi – satu objek
66

7+
<<<<<<< HEAD
78
Apakah mungkin untuk membuat fungsi `A` dan fungsi `B` seperti `new A()==new B()`?
9+
=======
10+
Is it possible to create functions `A` and `B` so that `new A() == new B()`?
11+
>>>>>>> 4d01fc20d4d82358e61518a31efe80dec9bb2602
812
913
```js no-beautify
1014
function A() { ... }

1-js/04-object-basics/09-object-toprimitive/article.md

Lines changed: 185 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ Itu batasan penting, karena hasil dari `obj1 + obj2` tidak bisa menjadi objek la
1010

1111
Misalnya. kita tidak dapat membuat objek yang mewakili vektor atau matriks (atau pencapaian atau apa pun), menambahkannya dan mengharapkan objek "dijumlahkan" sebagai hasilnya. Prestasi arsitektur seperti itu secara otomatis "di luar papan".
1212

13+
<<<<<<< HEAD
1314
Jadi, karena kita tidak bisa berbuat banyak di sini, tidak ada matematika dengan objek dalam proyek nyata. Ketika itu terjadi, biasanya karena kesalahan pengkodean.
15+
=======
16+
E.g. we can't make objects representing vectors or matrices (or achievements or whatever), add them and expect a "summed" object as the result. Such architectural feats are automatically "off the board".
17+
>>>>>>> 4d01fc20d4d82358e61518a31efe80dec9bb2602
1418
1519
Dalam bab ini kita akan membahas bagaimana sebuah objek dikonversi ke primitif dan bagaimana menyesuaikannya.
1620

@@ -97,5 +101,185 @@ Tidak ada petunjuk "boolean" (semua objek `benar` dalam konteks boolean) atau ya
97101
Mari kita mulai dari cara pertama. Ada simbol bawaan bernama `Symbol.toPrimitive` yang harus digunakan untuk menamai metode konversi, seperti ini:
98102
99103
```js
104+
<<<<<<< HEAD
100105
obj[Simbol.toPrimitif] = fungsi(petunjuk) {
101-
// dia
106+
// dia
107+
=======
108+
obj[Symbol.toPrimitive] = function(hint) {
109+
// here goes the code to convert this object to a primitive
110+
// it must return a primitive value
111+
// hint = one of "string", "number", "default"
112+
};
113+
```
114+
115+
If the method `Symbol.toPrimitive` exists, it's used for all hints, and no more methods are needed.
116+
117+
For instance, here `user` object implements it:
118+
119+
```js run
120+
let user = {
121+
name: "John",
122+
money: 1000,
123+
124+
[Symbol.toPrimitive](hint) {
125+
alert(`hint: ${hint}`);
126+
return hint == "string" ? `{name: "${this.name}"}` : this.money;
127+
}
128+
};
129+
130+
// conversions demo:
131+
alert(user); // hint: string -> {name: "John"}
132+
alert(+user); // hint: number -> 1000
133+
alert(user + 500); // hint: default -> 1500
134+
```
135+
136+
As we can see from the code, `user` becomes a self-descriptive string or a money amount depending on the conversion. The single method `user[Symbol.toPrimitive]` handles all conversion cases.
137+
138+
139+
## toString/valueOf
140+
141+
If there's no `Symbol.toPrimitive` then JavaScript tries to find methods `toString` and `valueOf`:
142+
143+
- For the "string" hint: `toString`, and if it doesn't exist, then `valueOf` (so `toString` has the priority for string conversions).
144+
- For other hints: `valueOf`, and if it doesn't exist, then `toString` (so `valueOf` has the priority for maths).
145+
146+
Methods `toString` and `valueOf` come from ancient times. They are not symbols (symbols did not exist that long ago), but rather "regular" string-named methods. They provide an alternative "old-style" way to implement the conversion.
147+
148+
These methods must return a primitive value. If `toString` or `valueOf` returns an object, then it's ignored (same as if there were no method).
149+
150+
By default, a plain object has following `toString` and `valueOf` methods:
151+
152+
- The `toString` method returns a string `"[object Object]"`.
153+
- The `valueOf` method returns the object itself.
154+
155+
Here's the demo:
156+
157+
```js run
158+
let user = {name: "John"};
159+
160+
alert(user); // [object Object]
161+
alert(user.valueOf() === user); // true
162+
```
163+
164+
So if we try to use an object as a string, like in an `alert` or so, then by default we see `[object Object]`.
165+
166+
The default `valueOf` is mentioned here only for the sake of completeness, to avoid any confusion. As you can see, it returns the object itself, and so is ignored. Don't ask me why, that's for historical reasons. So we can assume it doesn't exist.
167+
168+
Let's implement these methods to customize the conversion.
169+
170+
For instance, here `user` does the same as above using a combination of `toString` and `valueOf` instead of `Symbol.toPrimitive`:
171+
172+
```js run
173+
let user = {
174+
name: "John",
175+
money: 1000,
176+
177+
// for hint="string"
178+
toString() {
179+
return `{name: "${this.name}"}`;
180+
},
181+
182+
// for hint="number" or "default"
183+
valueOf() {
184+
return this.money;
185+
}
186+
187+
};
188+
189+
alert(user); // toString -> {name: "John"}
190+
alert(+user); // valueOf -> 1000
191+
alert(user + 500); // valueOf -> 1500
192+
```
193+
194+
As we can see, the behavior is the same as the previous example with `Symbol.toPrimitive`.
195+
196+
Often we want a single "catch-all" place to handle all primitive conversions. In this case, we can implement `toString` only, like this:
197+
198+
```js run
199+
let user = {
200+
name: "John",
201+
202+
toString() {
203+
return this.name;
204+
}
205+
};
206+
207+
alert(user); // toString -> John
208+
alert(user + 500); // toString -> John500
209+
```
210+
211+
In the absence of `Symbol.toPrimitive` and `valueOf`, `toString` will handle all primitive conversions.
212+
213+
### A conversion can return any primitive type
214+
215+
The important thing to know about all primitive-conversion methods is that they do not necessarily return the "hinted" primitive.
216+
217+
There is no control whether `toString` returns exactly a string, or whether `Symbol.toPrimitive` method returns a number for a hint `"number"`.
218+
219+
The only mandatory thing: these methods must return a primitive, not an object.
220+
221+
```smart header="Historical notes"
222+
For historical reasons, if `toString` or `valueOf` returns an object, there's no error, but such value is ignored (like if the method didn't exist). That's because in ancient times there was no good "error" concept in JavaScript.
223+
224+
In contrast, `Symbol.toPrimitive` *must* return a primitive, otherwise there will be an error.
225+
```
226+
227+
## Further conversions
228+
229+
As we know already, many operators and functions perform type conversions, e.g. multiplication `*` converts operands to numbers.
230+
231+
If we pass an object as an argument, then there are two stages:
232+
1. The object is converted to a primitive (using the rules described above).
233+
2. If the resulting primitive isn't of the right type, it's converted.
234+
235+
For instance:
236+
237+
```js run
238+
let obj = {
239+
// toString handles all conversions in the absence of other methods
240+
toString() {
241+
return "2";
242+
}
243+
};
244+
245+
alert(obj * 2); // 4, object converted to primitive "2", then multiplication made it a number
246+
```
247+
248+
1. The multiplication `obj * 2` first converts the object to primitive (that's a string `"2"`).
249+
2. Then `"2" * 2` becomes `2 * 2` (the string is converted to number).
250+
251+
Binary plus will concatenate strings in the same situation, as it gladly accepts a string:
252+
253+
```js run
254+
let obj = {
255+
toString() {
256+
return "2";
257+
}
258+
};
259+
260+
alert(obj + 2); // 22 ("2" + 2), conversion to primitive returned a string => concatenation
261+
```
262+
263+
## Summary
264+
265+
The object-to-primitive conversion is called automatically by many built-in functions and operators that expect a primitive as a value.
266+
267+
There are 3 types (hints) of it:
268+
- `"string"` (for `alert` and other operations that need a string)
269+
- `"number"` (for maths)
270+
- `"default"` (few operators)
271+
272+
The specification describes explicitly which operator uses which hint. There are very few operators that "don't know what to expect" and use the `"default"` hint. Usually for built-in objects `"default"` hint is handled the same way as `"number"`, so in practice the last two are often merged together.
273+
274+
The conversion algorithm is:
275+
276+
1. Call `obj[Symbol.toPrimitive](hint)` if the method exists,
277+
2. Otherwise if hint is `"string"`
278+
- try `obj.toString()` and `obj.valueOf()`, whatever exists.
279+
3. Otherwise if hint is `"number"` or `"default"`
280+
- try `obj.valueOf()` and `obj.toString()`, whatever exists.
281+
282+
In practice, it's often enough to implement only `obj.toString()` as a "catch-all" method for string conversions that should return a "human-readable" representation of an object, for logging or debugging purposes.
283+
284+
As for math operations, JavaScript doesn't provide a way to "override" them using methods, so real life projects rarely use them on objects.
285+
>>>>>>> 4d01fc20d4d82358e61518a31efe80dec9bb2602

1-js/05-data-types/02-number/article.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ Dalam JavaScript modern, ada dua tipe angka:
44

55
1. Angka regular di JavaScript yang disimpan dalam format 64-bit [IEEE-754](https://en.wikipedia.org/wiki/IEEE_754-2008_revision), juga dikenal sebagai "angka double precision floating point". Inilah angka yang kita paling sering kita pakai, dan kita akan bahas tentang mereka di bab ini.
66

7+
<<<<<<< HEAD
78
2. Angka BigInt, untuk mewakili integer dengan panjang sembarang. Mereka kadang dibutuhkan, karena angka regular tak bisa lebih dari <code>2<sup>53</sup></code> atau kurang dari <code>-2<sup>53</sup></code>. Karena bigint dipakai di sedikit area spesial, kita khususkan mereka bab spesial <info:bigint>.
9+
=======
10+
2. BigInt numbers, to represent integers of arbitrary length. They are sometimes needed, because a regular number can't safely exceed <code>2<sup>53</sup></code> or be less than <code>-2<sup>53</sup></code>. As bigints are used in few special areas, we devote them a special chapter <info:bigint>.
11+
>>>>>>> 4d01fc20d4d82358e61518a31efe80dec9bb2602
812
913
Jadi di sini kita akan bahas angka regular. Ayo perluas pengetahuan kita tentang mereka.
1014

@@ -37,8 +41,8 @@ alert( 7.3e9 ); // 7.3 milyar (7,300,000,000)
3741
Dengan kata lain, `"e"` kalikan angkanya dengan `1` dengan jumlah nol yang diberikan.
3842

3943
```js
40-
1e3 = 1 * 1000 // e3 means *1000
41-
1.23e6 = 1.23 * 1000000 // e6 means *1000000
44+
1e3 === 1 * 1000; // e3 means *1000
45+
1.23e6 === 1.23 * 1000000; // e6 means *1000000
4246
```
4347

4448
Sekarang ayo tulis sesuatu lebih kecil. Katakan, 1 microsecond (sepersejuta second):
@@ -53,16 +57,28 @@ Sama seperti sebelumnya, memakai `"e"` bisa membantu. Jika kita ingin menghindar
5357
let ms = 1e-6; // enam nol di sebelah kiri dari 1
5458
```
5559

60+
<<<<<<< HEAD
5661
Jika kita hitung nol di `0.000001`, ada 6 dari mereka. Jadi alaminya `1e-6`.
62+
=======
63+
If we count the zeroes in `0.000001`, there are 6 of them. So naturally it's `1e-6`.
64+
>>>>>>> 4d01fc20d4d82358e61518a31efe80dec9bb2602
5765
5866
Dengan kata lain, angka negatif setelah `"e"` artinya pembagian 1 dengan jumlah nol yang diberikan:
5967

6068
```js
69+
<<<<<<< HEAD
6170
// -3 membagi 1 dengan 3 nol
6271
1e-3 = 1 / 1000 (=0.001)
6372

6473
// -6 membagi 1 dengan 6 nol
6574
1.23e-6 = 1.23 / 1000000 (=0.00000123)
75+
=======
76+
// -3 divides by 1 with 3 zeroes
77+
1e-3 === 1 / 1000; // 0.001
78+
79+
// -6 divides by 1 with 6 zeroes
80+
1.23e-6 === 1.23 / 1000000; // 0.00000123
81+
>>>>>>> 4d01fc20d4d82358e61518a31efe80dec9bb2602
6682
```
6783

6884
### Hex, angka binary dan octal
@@ -117,7 +133,12 @@ Tolong ingat bahwa dua dot di `123456..toString(36)` bukan typo. Jika kita mau m
117133
118134
Jika kita menaruh dot tunggal: `123456.toString(36)`, maka akan ada galat, karena syntax JavaScript berimplikasi bahwa bagian desimal setelah dot pertama. Dan jika kita menaruh satu dot lagi, maka JavaScript tahu bahwa bagian desimal kosong dan sekarang pergi ke metode.
119135
136+
<<<<<<< HEAD
120137
Juga bisa menulis `(123456).toString(36)`.
138+
=======
139+
Also could write `(123456).toString(36)`.
140+
141+
>>>>>>> 4d01fc20d4d82358e61518a31efe80dec9bb2602
121142
```
122143

123144
## Pembulatan
@@ -328,7 +349,11 @@ let num = +prompt("Enter a number", '');
328349
alert( isFinite(num) );
329350
```
330351

352+
<<<<<<< HEAD
331353
Harap dicatat bahwa string kosong atau spasi-saja diperlakukan sebagai `0` dalam semua fungsi numerik termasuk` isFinite`.
354+
=======
355+
Please note that an empty or a space-only string is treated as `0` in all numeric functions including `isFinite`.
356+
>>>>>>> 4d01fc20d4d82358e61518a31efe80dec9bb2602
332357

333358
```smart header="Dibandingkan dengan `Object.is`"
334359

1-js/05-data-types/05-array-methods/12-reduce-object/task.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ nilai penting: 4
44

55
# Buatlah objek dengan kunci dari array
66

7+
<<<<<<< HEAD
78
Anggaplah kita menerima sebuah array dari user didalam form `{id:..., name:..., age... }`.
9+
=======
10+
Let's say we received an array of users in the form `{id:..., name:..., age:... }`.
11+
>>>>>>> 4d01fc20d4d82358e61518a31efe80dec9bb2602
812
913
Buatlah sebuah fungsi `groupById(arr)` yang membuat sebuah objek, dengan `id` sebagai key/kunci, dan item array sebagai nilai
1014

0 commit comments

Comments
 (0)