Skip to content

Commit 2dd654e

Browse files
authored
Merge pull request #162 from javascript-tutorial/sync-dccca58f
Sync with upstream @ dccca58
2 parents 6354241 + 375ddfc commit 2dd654e

File tree

24 files changed

+236
-37
lines changed

24 files changed

+236
-37
lines changed

1-js/03-code-quality/02-coding-style/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ Berikut contoh file `.eslintrc`:
328328
},
329329
"rules": {
330330
"no-console": 0,
331-
"indent": ["warning", 2]
331+
"indent": 2
332332
}
333333
}
334334
```

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ Sebenarnya, ada dua bagian dari Babel:
2929

3030
Seperti disebutkan diatas, JavaScript adalah sebuah bahasa pemrograman yang sangat dinamis. Skrip-skrip baru terus ditambahkan kedalam JavaScript dengan tujuan untuk membuat fungsi-fungsi baru menjadi dapat dibaca oleh penerjemah JavaScript standar.
3131

32+
<<<<<<< HEAD
3233
Skrip-skrip tambahan inilah yang disebut Polyfill. Skrip-skrip ini biasanya berupa fungsi-fungsi yang bertujuan menambah atau memodifikasi perbendaharaan JavaScript standar agar mampu mengenal fitur-fitur modern.
34+
=======
35+
New language features may include not only syntax constructs, but also built-in functions.
36+
The transpiler rewrites the code, transforming syntax constructs into older ones. But as for new built-in functions, we need to implement them. JavaScript is a highly dynamic language, scripts may add/modify any functions, so that they behave according to the modern standard.
37+
>>>>>>> dccca58f268ad6d5a6f2160613a8ea3c5cd53a2d
3338
3439
Polifyll yang sering digunakan:
3540

1-js/04-object-basics/03-garbage-collection/article.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ Sederhananya, sebuah nilai yang "terjangkau" adalah mereka yang masih dapat diak
2323

2424
2. Nilai lainnya dianggap terjangkau jika dapat dijangkau dari sebuah _root_ melalui sebuah rujukkan atau rantai rujukkan.
2525

26+
<<<<<<< HEAD
2627
Contoh, jika terdapat sebuah objek didalam global variabel, dan objek tersebut memiliki sebuah properti yang mereferensi objek lain, objek itu dianggap dapat dijangkau. Dan referensinya juga bisa dijangkau. Contoh lengkap dibawah ini.
28+
=======
29+
For instance, if there's an object in a global variable, and that object has a property referencing another object, *that* object is considered reachable. And those that it references are also reachable. Detailed examples to follow.
30+
>>>>>>> dccca58f268ad6d5a6f2160613a8ea3c5cd53a2d
2731
2832
Ada sebuah _background process_ di _engine_ JavaScript yang disebut [_garbage collector_](https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)). Ia mengamati seluruh objek dan menyingkirkan semua yang sudah tak terjangkau.
2933

1-js/04-object-basics/07-optional-chaining/article.md

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@ The optional chaining `?.` is a safe way to access nested object properties, eve
1414
1515
Jika kamu baru saja membaca tutorial dan belajar Javascript, mungkin masalahnya belum ketemu, tapi itu sudah biasa.
1616

17+
<<<<<<< HEAD
1718
<<<<<<< HEAD
1819
Contoh, beberapa dari pengguna kita punya alamat, tapi beberapa tidak memberikannya. Lalu kita tidak bisa dengan mudah menggunakan `user.address.street`:
1920

2021
```js run
2122
let user = {}; // penggunanya tidak memiliki alamat
2223
=======
2324
As an example, consider objects for user data. Most of our users have addresses in `user.address` property, with the street `user.address.street`, but some did not provide them.
25+
=======
26+
As an example, let's say we have `user` objects that hold the information about our users.
27+
>>>>>>> dccca58f268ad6d5a6f2160613a8ea3c5cd53a2d
28+
29+
Most of our users have addresses in `user.address` property, with the street `user.address.street`, but some did not provide them.
2430
25-
In such case, when we attempt to get `user.address.street`, we may get an error:
31+
In such case, when we attempt to get `user.address.street`, and the user happens to be without an address, we get an error:
2632
2733
```js run
2834
let user = {}; // a user without "address" property
@@ -31,6 +37,7 @@ let user = {}; // a user without "address" property
3137
alert(user.address.street); // Error!
3238
```
3339
40+
<<<<<<< HEAD
3441
<<<<<<< HEAD
3542
Atau, didalam pengembangan, kita ingin untuk mendapatkan informasi tentang sebuah elemen didalam halaman, tapi elemennya tidak ada:
3643
@@ -44,27 +51,32 @@ Sebelum `?.` muncul, operator `&&` digunakan untuk berurusan dengan hal itu.
4451
Contoh:
4552
=======
4653
That's the expected result, JavaScript works like this. As `user.address` is `undefined`, the attempt to get `user.address.street` fails with an error. Although, in many practical cases we'd prefer to get `undefined` instead of an error here (meaning "no street").
54+
=======
55+
That's the expected result. JavaScript works like this. As `user.address` is `undefined`, an attempt to get `user.address.street` fails with an error.
56+
57+
In many practical cases we'd prefer to get `undefined` instead of an error here (meaning "no street").
58+
>>>>>>> dccca58f268ad6d5a6f2160613a8ea3c5cd53a2d
4759
48-
...And another example. In the web development, we may need the information about an element on the page. The element is returned by `document.querySelector('.elem')`, and the catch is again - that it sometimes doesn't exist:
60+
...And another example. In the web development, we can get an object that corresponds to a web page element using a special method call, such as `document.querySelector('.elem')`, and it returns `null` when there's no such element.
4961

5062
```js run
51-
// the result of the call document.querySelector('.elem') may be an object or null
63+
// document.querySelector('.elem') is null if there's no element
5264
let html = document.querySelector('.elem').innerHTML; // error if it's null
5365
```
5466

55-
Once again, we may want to avoid the error in such case.
67+
Once again, if the element doesn't exist, we'll get an error accessing `.innerHTML` of `null`. And in some cases, when the absence of the element is normal, we'd like to avoid the error and just accept `html = null` as the result.
5668
5769
How can we do this?
5870
59-
The obvious solution would be to check the value using `if` or the conditional operator `?`, before accessing it, like this:
71+
The obvious solution would be to check the value using `if` or the conditional operator `?`, before accessing its property, like this:
6072
6173
```js
6274
let user = {};
6375
6476
alert(user.address ? user.address.street : undefined);
6577
```
6678
67-
...But that's quite inelegant. As you can see, the `user.address` is duplicated in the code. For more deeply nested properties, that becomes a problem.
79+
It works, there's no error... But it's quite inelegant. As you can see, the `"user.address"` appears twice in the code. For more deeply nested properties, that becomes a problem as more repetitions are required.
6880
6981
E.g. let's try getting `user.address.street.name`.
7082

@@ -76,10 +88,14 @@ let user = {}; // user has no address
7688
alert(user.address ? user.address.street ? user.address.street.name : null : null);
7789
```
7890

79-
That looks awful.
91+
That's just awful, one may even have problems understanding such code.
8092
93+
<<<<<<< HEAD
8194
Before the optional chaining `?.` was added to the language, people used the `&&` operator for such cases:
8295
>>>>>>> d6e88647b42992f204f57401160ebae92b358c0d
96+
=======
97+
Don't even care to, as there's a better way to write it, using the `&&` operator:
98+
>>>>>>> dccca58f268ad6d5a6f2160613a8ea3c5cd53a2d
8399
84100
```js run
85101
let user = {}; // pengguna tidak memiliki alamat
@@ -92,20 +108,35 @@ Dan juga selutuh path ke propertinya memastikan seluruh komponen ada, tapi terla
92108
=======
93109
AND'ing the whole path to the property ensures that all components exist (if not, the evaluation stops), but also isn't ideal.
94110
95-
As you can see, the property names are still duplicated in the code. E.g. in the code above, `user.address` appears three times.
111+
As you can see, property names are still duplicated in the code. E.g. in the code above, `user.address` appears three times.
96112
113+
<<<<<<< HEAD
97114
And now, finally, the optional chaining comes to the rescue!
98115
>>>>>>> d6e88647b42992f204f57401160ebae92b358c0d
116+
=======
117+
That's why the optional chaining `?.` was added to the language. To solve this problem once and for all!
118+
>>>>>>> dccca58f268ad6d5a6f2160613a8ea3c5cd53a2d
99119

100120
## Rantai opsional
101121

122+
<<<<<<< HEAD
102123
Rantai opsional `?.` menghentikan evaluasi dan mengembalikan `undefined` jika bagian sebelum `?.` adalah `undefined` atau `null`.
124+
=======
125+
The optional chaining `?.` stops the evaluation if the part before `?.` is `undefined` or `null` and returns that part.
126+
>>>>>>> dccca58f268ad6d5a6f2160613a8ea3c5cd53a2d
103127

104128
**Selanjutnya di artikel ini, untuk meringkas, kita akan bilang bahwa sesuatu "ada" jika itu bukan `null` dan bukan `undefined`.**
105129

130+
<<<<<<< HEAD
106131
<<<<<<< HEAD
107132
Ini ada cara teraman untuk mengakses `user.address.street`:
108133
=======
134+
=======
135+
In other words, `value?.prop`:
136+
- is the same as `value.prop` if `value` exists,
137+
- otherwise (when `value` is `undefined/null`) it returns that `value`.
138+
139+
>>>>>>> dccca58f268ad6d5a6f2160613a8ea3c5cd53a2d
109140
Here's the safe way to access `user.address.street` using `?.`:
110141
>>>>>>> d6e88647b42992f204f57401160ebae92b358c0d
111142
@@ -132,6 +163,7 @@ alert( user?.address.street ); // undefined
132163
133164
Perhatikan: sintaks `?.` membuat nilai opsional sebelumnya, tapi tidak setelahnya.
134165
166+
<<<<<<< HEAD
135167
<<<<<<< HEAD
136168
Didalam contoh diatas, `user?.` membolehkan hanya `user` untuk `null/undefined`.
137169
=======
@@ -142,6 +174,9 @@ Disisi lain, jika `user` ada, lalu itu harus memiliki properti `user.address`, s
142174
143175
```warn header="Jangan terlalu berlebihan menggunakan rantai opsional"
144176
Kita harus menggunakan `?.` hanya dimana sesuatu itu tidak apa-apa bila tidak ada.
177+
=======
178+
E.g. in `user?.address.street.name` the `?.` allows `user` to be `null/undefined`, but it's all it does. Further properties are accessed in a regular way. If we want some of them to be optional, then we'll need to replace more `.` with `?.`.
179+
>>>>>>> dccca58f268ad6d5a6f2160613a8ea3c5cd53a2d
145180
146181
<<<<<<< HEAD
147182
Contoh, jika berdasarkan logika koding kita objek `user` harus ada, tapi `address` bersifat opsional, lalu `user.address?.street` akan lebih baik.
@@ -210,17 +245,20 @@ Contoh, `?.()` digunakan untuk memanggil fungsi yang mungkin saja tidak ada.
210245
Di kode dibawah, beberapa user mungkin memiliki method `admin`, dan beberapa tidak:
211246

212247
```js run
213-
let user1 = {
248+
let userAdmin = {
214249
admin() {
215250
alert("I am admin");
216251
}
217-
}
252+
};
253+
254+
let userGuest = {};
218255

219-
let user2 = {};
256+
*!*
257+
userAdmin.admin?.(); // I am admin
258+
*/!*
220259

221260
*!*
222-
user1.admin?.(); // I am admin
223-
user2.admin?.();
261+
userGuest.admin?.(); // nothing (no such method)
224262
*/!*
225263
```
226264

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,11 @@ Beberapa contoh:
406406
alert( Math.pow(2, 10) ); // 2 in power 10 = 1024
407407
```
408408

409+
<<<<<<< HEAD
409410
Ada lebih banyak fungsi dan konstanta dalam objek `Math`, termasuk trigonometri, yang dapat Anda temukan di [docs untuk objek Math](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Math).
411+
=======
412+
There are more functions and constants in `Math` object, including trigonometry, which you can find in the [docs for the Math object](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Math).
413+
>>>>>>> dccca58f268ad6d5a6f2160613a8ea3c5cd53a2d
410414

411415
## Kesimpulan
412416

1-js/05-data-types/08-weakmap-weakset/article.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ let array = [ john ];
3030
john = null; // tulis ulang referensinya
3131

3232
*!*
33+
<<<<<<< HEAD
3334
// john disimpan didalam array, jadi itu tidak dibuang
3435
// kita bisa mendapatkannya sebagai array[0]
36+
=======
37+
// the object previously referenced by john is stored inside the array
38+
// therefore it won't be garbage-collected
39+
// we can get it as array[0]
40+
>>>>>>> dccca58f268ad6d5a6f2160613a8ea3c5cd53a2d
3541
*/!*
3642
```
3743

1-js/06-advanced-functions/04-var/article.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ function sayHi() {
7878
}
7979

8080
sayHi();
81+
<<<<<<< HEAD
8182
alert(phrase); // Error: frasa tidak terdefinisi (periksa Developer Console)
83+
=======
84+
alert(phrase); // Error: phrase is not defined
85+
>>>>>>> dccca58f268ad6d5a6f2160613a8ea3c5cd53a2d
8286
```
8387

8488
Seperti yang bisa kita lihat `var` menembus `if`, `for` atau blok kode lainnya. Itu karena sejak dahulu di blok Javascript tidak memiliki Lingkungan Leksikal. dan `var` adalah sisanya.
@@ -267,8 +271,13 @@ Dalam semua kasus diatas kami mendeklarasikan sebuah Ekspresi fungsi dan menjala
267271

268272
Ada dua perbedaan utama dari `var` dibandingkan dengan `let/const`;
269273

274+
<<<<<<< HEAD
270275
1. `var` variabel tidak memiliki ruang lingkup blok, mereka terlihat minimum pada tingkat fungsi.
271276
2. Deklarasi `var` diproses saat fungsi dimulai (skrip dimulai untuk global).
277+
=======
278+
1. `var` variables have no block scope, their visibility is scoped to current function, or global, if declared outside function.
279+
2. `var` declarations are processed at function start (script start for globals).
280+
>>>>>>> dccca58f268ad6d5a6f2160613a8ea3c5cd53a2d
272281
273282
Ada satu perbedaan kecil terkait objek global, yang akan kita bahas pada bab selanjutnya.
274283

1-js/06-advanced-functions/05-global-object/article.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ Objek global menyediakan variabel dan fungsi yang bisa didapatkan dimana saja. S
55

66
Di dalam browser ia dinamakan `window`, untuk Node.js `global`, untuk lingkungan lainnya ia mungkin mempunyai nama lain.
77

8+
<<<<<<< HEAD
89
<<<<<<< HEAD
910
Akhir-akhir ini, `globalThis` ditambahkan ke bahasanya, sebagai nama standar untuk objek global, yang harus di dukung di semua lingkungan. Di browser tertentu, ya itu non-Chromium Edge, `globalThis` belum didukung, tapi bisa dengan mudah dipolyfill.
1011
=======
1112
Recently, `globalThis` was added to the language, as a standardized name for a global object, that should be supported across all environments. It's supported in all major browsers.
1213
>>>>>>> f830bc5d9454d85829e011d914f215eb5896579a
14+
=======
15+
Recently, `globalThis` was added to the language, as a standardized name for a global object, that should be supported across all environments. It's supported in all major browsers.
16+
>>>>>>> dccca58f268ad6d5a6f2160613a8ea3c5cd53a2d
1317
1418
Kita akan memakai `window` disini, dengan anggapan bahwa lingkungan kita adalah browser. Jika script kamu mungkin digunakan di lingkungan lain, lebih baik menggunakan `globalThis`.
1519

@@ -29,7 +33,13 @@ var gVar = 5;
2933
alert(window.gVar); // 5 (menjadi properti objek global)
3034
```
3135

36+
<<<<<<< HEAD
3237
Mohon jangan bergantung dengan itu! Perilaku ini ada untuk alasan kompatibilitas. Script modern menggunakan [JavaScript modules](info:modules) dimana hal-hal tersebut tidak terjadi.
38+
=======
39+
The same effect have function declarations (statements with `function` keyword in the main code flow, not function expressions).
40+
41+
Please don't rely on that! This behavior exists for compatibility reasons. Modern scripts use [JavaScript modules](info:modules) where such thing doesn't happen.
42+
>>>>>>> dccca58f268ad6d5a6f2160613a8ea3c5cd53a2d
3343
3444
Jika kita menggunakan `let`, hal tersebut tidak akan terjadi:
3545

1-js/06-advanced-functions/06-function-object/article.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,11 @@ Jika fungsinya di deklarasikan sebagai ekspresi fungsi (tidak didalam alur kode
347347

348348
Juga, fungsi mungkin memiliki properti tambahan. Beberapa librari Javascript yang cukup terkenal banyak menggunakan fitur ini.
349349

350+
<<<<<<< HEAD
350351
Mereka membuat sebuah fungsi "utama" dan mengkaitkannya dengan fungsi "pembantu". Contoh librari [jQuery](https://jquery.com) menciptakan fungsi bernama `$`. Librari The [lodash](https://lodash.com) membuat sebuah fungsi `_` dan lalu menambahkan `_.clone`, `_.keyBy`dan properti lainnya kedalamnya (lihat [dokumentasinya](https://lodash.com/docs) ketika kamu mau tau lebih dalam). Sebenarnya, mereka melakukannya untuk mengurangi penggunaan dari ruang global, jadi librari tunggal itu hanya menggunakan satu variabel global. Itu mengurangi kemungkinan dari konflik penamaan variabel.
352+
=======
353+
They create a "main" function and attach many other "helper" functions to it. For instance, the [jQuery](https://jquery.com) library creates a function named `$`. The [lodash](https://lodash.com) library creates a function `_`, and then adds `_.clone`, `_.keyBy` and other properties to it (see the [docs](https://lodash.com/docs) when you want to learn more about them). Actually, they do it to lessen their pollution of the global space, so that a single library gives only one global variable. That reduces the possibility of naming conflicts.
354+
>>>>>>> dccca58f268ad6d5a6f2160613a8ea3c5cd53a2d
351355
352356

353357
Jadi, sebuah fungsi bisa melakukan hal-hal yang berguna dengan dirinya-sendiri dan juga membawa setumpuk fungsionalitas didalam propertinya sendiri.

1-js/06-advanced-functions/07-new-function/article.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ Bagaimana jika itu bisa mengakses variabel luar?
9292

9393
Masalahnya adalah saat Javascript belum dipublikasikan untuk produksi, itu akan dikompresi menggunakan *minifier* -- sebuah program spesial yang mengecilkan ukuran kode dengan menghapus komentar-komentar, spasi dan -- yang paling penting, menamai variabel lokal menjadi lebih pendek.
9494

95+
<<<<<<< HEAD
9596
Contoh, jika sebuah fungsi mempunyai `let userName`, minifier akan mengganti itu dengan `let a` (atau huruf lainnya jika tidak hurufnya tidak tersedia), dan melakukannya dimanapun. Sebenarnya itu adalah yang yang aman untuk dilakukan, karena variabelnya lokal, tidak ada sesuatu dari luar fungsinya yang bisa mengaksesnya. Dan didalam fungsinya, minifier mengganti seluruh penamaan variabelnya. Minifier cukup pintar, mereka menganalisa struktur kodenya, jadi mereka tidak akan merusak apapun. Minifier bukanlah hal bodoh yang hanya akan mencari-dan-mengganti.
97+
=======
98+
For instance, if a function has `let userName`, minifier replaces it with `let a` (or another letter if this one is occupied), and does it everywhere. That's usually a safe thing to do, because the variable is local, nothing outside the function can access it. And inside the function, minifier replaces every mention of it. Minifiers are smart, they analyze the code structure, so they don't break anything. They're not just a dumb find-and-replace.
99+
>>>>>>> dccca58f268ad6d5a6f2160613a8ea3c5cd53a2d
96100
97101
Jadi jika `new Function` mempunyai akses ke variabel luar, itu tidak akan bisa menemukan `userName` yang telah dinamai ulang.
98102

0 commit comments

Comments
 (0)