Skip to content

Commit 0595120

Browse files
authored
Merge pull request #55 from javascript-tutorial/sync-5b195795
Sync with upstream @ 5b19579
2 parents 1604958 + 7fb85ca commit 0595120

File tree

68 files changed

+369
-234
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+369
-234
lines changed

1-js/01-getting-started/1-intro/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Engine sangat rumit. Tapi basicnya mudah.
3838
2. Lalu ia mengkonversi ("mengkompilasi") script tersebut menjadi bahasa mesin.
3939
3. Dan kemudian kode mesin berjalan, lumayan cepat.
4040
41-
Engine melakukan optimisasi di setiap langkah proses. Dia bahkan memperhatikan script yang telah dikompilasi saat sedang berjalan, menganalisa data yang mengalir di dalam, dan melakukan optimisasi ke kode mesin berdasarkan pengetahuan itu. Ketika selesai, script berjalan lumayan cepat.
41+
Engine melakukan optimisasi di setiap langkah proses. Dia bahkan memperhatikan script yang telah dikompilasi saat sedang berjalan, menganalisa data yang mengalir di dalam, dan melakukan optimisasi ke kode mesin berdasarkan pengetahuan itu.
4242
```
4343

4444
## Apa yang bisa dilakukan *in-browser JavaScript*?

1-js/01-getting-started/4-devtools/article.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@ Tampilan persisnya tools pengembang tergantung versi Chrome kamu. Ia berubah dar
2929
- Di sini kita bisa melihat pesan error berwarna merah. Di sini, scriptnya mengandung perintah asing "lalala".
3030
- Di kanan, ada link yang bisa diklik ke sumber `bug.html:12` dengan nomor baris di mana error itu muncul.
3131

32-
Di bawah pesan error, ada simbol `>` berwarna biru. Ia menandakan "command line" di mana kita bisa mengetik perintah JavaScript. Tekan `key:Enter` untuk menjalankannya (`key:Shift+Enter` untuk menginput perintah multi-baris).
32+
Di bawah pesan error, ada simbol `>` berwarna biru. Ia menandakan "command line" di mana kita bisa mengetik perintah JavaScript. Tekan `key:Enter` untuk menjalankannya.
3333

3434
Sekarang kita bisa melihat error, dan itu sudah cukup untuk permulaan. Kita nanti akan kembali ke tools pengembang dan mengcover debugging lebih dalam di bab <info:debugging-chrome>.
3535

36+
```smart header="Multi-line input"
37+
Usually, when we put a line of code into the console, and then press `key:Enter`, it executes.
38+
39+
To insert multiple lines, press `key:Shift+Enter`. This way one can enter long fragments of JavaScript code.
40+
```
3641

3742
## Firefox, Edge, dan lainnya
3843

@@ -50,12 +55,6 @@ Buka Preferences dan pergi ke "Advanced" pane. Di sana ada checkbox di sebelah b
5055

5156
Sekarang `key:Cmd+Opt+C` bisa mentoggle konsol. Lalu, menu "Develop" muncul pada menu item di atas. Ia punya banyak perintah dan opsi.
5257

53-
```smart header="Input baris-ganda"
54-
Biasanya, ketika kita menaruh sebaris kode ke konsol, dan menekan `key:Enter`, dia akan berjalan.
55-
56-
Untuk menyisipkan lebih dari satu baris, tekan `key:Shift+Enter`. Dengan cara ini kamu bisa mengenter fragment yang panjang dari kode JavaScript.
57-
```
58-
5958
## Kesimpulan
6059

6160
- Tools pengembang memungkinkan kita melihat error, menjalankan perintah, memeriksa variabel, dan sebagainya.

1-js/02-first-steps/05-types/article.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,33 @@ Nilai numerik spesial formalnya merupakan bagian dari tipe "number". Tentu saja
6262

6363
Kita akan melihat lebih tentang cara bekerja dengan angka di bab <info:number>.
6464

65+
## BigInt
66+
67+
Di JavaScript, tipe "number" tidak bisa mewakili nilai integer yang lebih dari <code>2<sup>53</sup></code> (atau kurang dari <code>-2<sup>53</sup></code> untuk negatives), itu batasan teknikal yang disebabkan representasi internal mereka. Itu sekitar 16 digit desimal, jadi untuk banyak tujuan limitasi itu bukan masalah, tapi kadang kita butuh butuh big number yang sangat besar, misanya: cryptography or microsecond-precision timestamps.
68+
69+
`BigInt` type was recently added to the language to represent integers of arbitrary length.
70+
71+
A `BigInt` is created by appending `n` to the end of an integer literal:
72+
73+
```js
74+
// the "n" at the end means it's a BigInt
75+
const bigInt = 1234567890123456789012345678901234567890n;
76+
```
77+
78+
As `BigInt` numbers are rarely needed, we devoted them a separate chapter <info:bigint>.
79+
80+
```smart header="Compatability issues"
81+
Right now `BigInt` is supported in Firefox and Chrome, but not in Safari/IE/Edge.
82+
```
83+
6584
## String
6685

6786
String di JavaScript harus dikelilingi petik.
6887

6988
```js
7089
let str = "Hello";
7190
let str2 = 'Single quotes are ok too';
72-
let phrase = `can embed ${str}`;
91+
let phrase = `can embed another ${str}`;
7392
```
7493

7594
Di JavaScript, ada 3 tipe petik.
@@ -198,6 +217,8 @@ typeof undefined // "undefined"
198217

199218
typeof 0 // "number"
200219

220+
typeof 10n // "bigint"
221+
201222
typeof true // "boolean"
202223

203224
typeof "foo" // "string"
@@ -223,12 +244,12 @@ Tiga baris terakhir mungkin butuh penjelasan tambahan:
223244
2. Hasil `typeof null` yaitu `"object"`. Itu salah. Ia merupakan error yang terkenal resmi dalam `typeof`, yang dijaga untuk kompatibilitas. Tentu saja, `null` bukanlah objek. Ia merupakan nilai spesial dengan tipe terpisah miliknya sendiri. Jadi, lagi, ini merupakan error dalam bahasa.
224245
3. Hasil dari `typeof alert` yaitu `"function"`, karena `alert` merupakan fungsi. Kita akan belajar fungsi di bab berikutnya di mana kita juga akan melihat bahwa tak ada tipe "fungsi" spesial di JavaScript. Fungsi merupakan bagian dari tipe objek. Tapi `typeof` memperlakukan mereka secara berbeda, yang mengembalikan `"fungsi"`. Itu tak sepenuhnya benar, tapi sangat nyaman pada praktiknya.
225246

226-
227247
## Kesimpulan
228248

229249
Ada 7 tipe data dasar dalam JavaScript.
230250

231251
- `number` untuk angka jenis manapun: integer atau floating-point.
252+
- `bigint` untuk angka integer dengan panjang sembarang.
232253
- `string` untuk string. String mungkin punya satu atau lebih karakter, tak ada tipe katakter tunggal terpisah.
233254
- `boolean` untuk `true`/`false`.
234255
- `null` untuk nilai tak-diketahui -- tipe mandiri yang punya nilai tunggal `null`.

1-js/02-first-steps/06-type-conversions/article.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,7 @@ alert( Number(false) ); // 0
8181

8282
Tolong diingat bahwa kelakuan `null` dan `undefined` berbeda di sini: `null` menjadi nol namun `undefined` menjadi `NaN`.
8383

84-
````smart header="Penambahan '+' mengkonkatenasi string"
85-
Hampir semua operasi matematik mengkonversi nilai ke angka. Pengecualian yang penting ialah penambahan `+`. Jika satu dari nilai yang ditambahkan berupa string, nilai lainnya juga dikonversi ke string.
86-
87-
Maka, ia mengkonkatenasi (menggabungkan) mereka:
88-
89-
```js run
90-
alert( 1 + '2' ); // '12' (string ke kanan)
91-
alert( '1' + 2 ); // '12' (string ke kiri)
92-
```
93-
94-
Ini cuma terjadi ketika setidaknya satu dari argumen yaitu string. Sebaliknya, nilai dikonversi ke angka.
95-
````
84+
Hampir semua operasi matematik melakukan konversi semacam ini, yang akan kita lihat di bab berikutnya.
9685

9786
## Boolean Conversion
9887

1-js/02-first-steps/08-comparison/1-comparison-questions/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ null === +"\n0\n" → false
1313
Beberapa alasan:
1414

1515
1. Sudah jelas, true.
16-
2. Pembandingan kamus, jadi false.
16+
2. Pembandingan kamus, jadi false. `"a"` lebih kecil dari `"p"`.
1717
3. Lagi, pembandingan kamus, karakter pertama `"2"` lebih besar dari karakter pertama `"1"`.
1818
4. Nilai `null` dan `undefined` selalu bernilai sama.
1919
5. Equalitas ketat memang ketat. Tipe berbeda dari kedua sisi menghasilkan false.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ Itu juga untuk keterbacaan yang lebih baik, karena lebih mudah melihat `function
355355
...Tapi jika Deklarasi Fungsi tak cocok untuk beberapa alasan, atau kita butuh deklarasi kondisional (kita sudah lihat contohnya), maka Expresi Fungsi sebaiknya digunakan.
356356
```
357357

358-
## Summary
358+
## Kesimpulan
359359

360360
- Fungsi adalah nilai. Mereka bisa diset, dikopi atau dideklarasi di kode manapun.
361361
- Jika fungsi dideklarasi sebagai pernyataan terpisah di aliran kode utama, ia disebut "Deklarasi Fungsi".

1-js/04-object-basics/04-object-methods/4-object-property-this/solution.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ The value of `this` is one for the whole function, code blocks and object litera
2222

2323
So `ref: this` actually takes current `this` of the function.
2424

25+
We can rewrite the function and return the same `this` with `undefined` value:
26+
27+
```js run
28+
function makeUser(){
29+
return this; // this time there's no object literal
30+
}
31+
32+
alert( makeUser().name ); // Error: Cannot read property 'name' of undefined
33+
```
34+
As you can see the result of `alert( makeUser().name )` is the same as the result of `alert( user.ref.name )` from the previous example.
35+
2536
Here's the opposite case:
2637

2738
```js run

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Numbers
22

3-
All numbers in JavaScript are stored in 64-bit format [IEEE-754](https://en.wikipedia.org/wiki/IEEE_754-2008_revision), also known as "double precision floating point numbers".
3+
In modern JavaScript, there are two types of numbers:
44

5-
Let's expand upon what we currently know about them.
5+
1. Regular numbers in JavaScript are stored in 64-bit format [IEEE-754](https://en.wikipedia.org/wiki/IEEE_754-2008_revision), also known as "double precision floating point numbers". These are numbers that we're using most of the time, and we'll talk about them in this chapter.
6+
7+
2. BigInt numbers, to represent integers of arbitrary length. They are sometimes needed, because a regular number can't 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>.
8+
9+
So here we'll talk about regular numbers. Let's expand our knowledge of them.
610

711
## More ways to write a number
812

@@ -29,14 +33,13 @@ In other words, `"e"` multiplies the number by `1` with the given zeroes count.
2933
1.23e6 = 1.23 * 1000000
3034
```
3135

32-
3336
Now let's write something very small. Say, 1 microsecond (one millionth of a second):
3437

3538
```js
3639
let ms = 0.000001;
3740
```
3841

39-
Just like before, using `"e"` can help. If we'd like to avoid writing the zeroes explicitly, we could say:
42+
Just like before, using `"e"` can help. If we'd like to avoid writing the zeroes explicitly, we could say the same as:
4043

4144
```js
4245
let ms = 1e-6; // six zeroes to the left from 1
@@ -271,13 +274,11 @@ JavaScript doesn't trigger an error in such events. It does its best to fit the
271274
```smart header="Two zeroes"
272275
Another funny consequence of the internal representation of numbers is the existence of two zeroes: `0` and `-0`.
273276

274-
That's because a sign is represented by a single bit, so every number can be positive or negative, including a zero.
277+
That's because a sign is represented by a single bit, so it can be set or not set for any number including a zero.
275278

276279
In most cases the distinction is unnoticeable, because operators are suited to treat them as the same.
277280
```
278281

279-
280-
281282
## Tests: isFinite and isNaN
282283

283284
Remember these two special numeric values?
@@ -409,10 +410,10 @@ There are more functions and constants in `Math` object, including trigonometry,
409410

410411
## Summary
411412

412-
To write big numbers:
413+
To write numbers with many zeroes:
413414

414-
- Append `"e"` with the zeroes count to the number. Like: `123e6` is `123` with 6 zeroes.
415-
- A negative number after `"e"` causes the number to be divided by 1 with given zeroes. That's for one-millionth or such.
415+
- Append `"e"` with the zeroes count to the number. Like: `123e6` is the same as `123` with 6 zeroes `123000000`.
416+
- A negative number after `"e"` causes the number to be divided by 1 with given zeroes. E.g. `123e-6` means `0.000123` (`123` millionth).
416417

417418
For different numeral systems:
418419

0 commit comments

Comments
 (0)