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/05-data-types/02-number/article.md
+28-28Lines changed: 28 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -16,89 +16,89 @@ Bayangkan kita harus menulis 1 milyar. Cara jelasnya begini:
16
16
let billion =1000000000;
17
17
```
18
18
19
-
But in real life, we usually avoid writing a long string of zeroes as it's easy to mistype. Also, we are lazy. We will usually write something like`"1bn"`for a billion or `"7.3bn"`for 7 billion 300 million. The same is true for most large numbers.
19
+
Tapi di kehidupan nyata, kita biasanya menghindari menulis string nol yang panjang karena rentan terjadi kesalahan. Selain itu, kita malas. Kita biasanya akan menulis sesuatu seperti`"1bn"`untuk milyar atau `"7.3bn"`untuk 7 milyar 300 juta. Sama halnya dengan angka besar lainnya.
20
20
21
-
In JavaScript, we shorten a number by appending the letter `"e"`to the number and specifying the zeroes count:
21
+
Di JavaScript, kita perpendek angka dengan menambah huruf `"e"`ke angka dan menspesifikasi jumlah nol:
22
22
23
23
```js run
24
-
let billion =1e9; // 1 billion, literally: 1 and 9 zeroes
24
+
let billion =1e9; // 1 milyar, literalnya: 1 dan 9 nol
25
25
26
-
alert( 7.3e9 ); // 7.3 billions (7,300,000,000)
26
+
alert( 7.3e9 ); // 7.3 milyar (7,300,000,000)
27
27
```
28
28
29
-
In other words, `"e"`multiplies the number by `1`with the given zeroes count.
29
+
Dengan kata lain, `"e"`kalikan angkanya dengan `1`dengan jumlah nol yang diberikan.
30
30
31
31
```js
32
32
1e3=1*1000
33
33
1.23e6=1.23*1000000
34
34
```
35
35
36
-
Now let's write something very small. Say, 1 microsecond (one millionth of a second):
36
+
Sekarang ayo tulis sesuatu lebih kecil. Katakan, 1 microsecond (sepersejuta second):
37
37
38
38
```js
39
39
let ms =0.000001;
40
40
```
41
41
42
-
Just like before, using`"e"`can help. If we'd like to avoid writing the zeroes explicitly, we could say the same as:
42
+
Sama seperti sebelumnya, memakai`"e"`bisa membantu. Jika kita ingin menghindari menulis nol eksplisit, kita bisa katakan hal yang sama:
43
43
44
44
```js
45
-
let ms =1e-6; //six zeroes to the left from 1
45
+
let ms =1e-6; //enam nol di sebelah kiri dari 1
46
46
```
47
47
48
-
If we count the zeroes in `0.000001`, there are 6 of them. So naturally it's`1e-6`.
48
+
Jika kita hitung nol di `0.000001`, ada 6 dari mereka. Jadi alaminya`1e-6`.
49
49
50
-
In other words, a negative number after `"e"`means a division by 1 with the given number of zeroes:
50
+
Dengan kata lain, angka negatif setelah `"e"`artinya pembagian 1 dengan jumlah nol yang diberikan:
51
51
52
52
```js
53
-
// -3 divides by 1 with 3 zeroes
53
+
// -3 membagi 1 dengan 3 nol
54
54
1e-3=1/1000 (=0.001)
55
55
56
-
// -6 divides by 1 with 6 zeroes
56
+
// -6 membagi 1 dengan 6 nol
57
57
1.23e-6=1.23/1000000 (=0.00000123)
58
58
```
59
59
60
-
### Hex, binary and octal numbers
60
+
### Hex, angka binary dan octal
61
61
62
-
[Hexadecimal](https://en.wikipedia.org/wiki/Hexadecimal)numbers are widely used in JavaScript to represent colors, encode characters, and for many other things. So naturally, there exists a shorter way to write them: `0x`and then the number.
62
+
Angka [Hexadecimal](https://en.wikipedia.org/wiki/Hexadecimal)secara luas dipakai di JavaScript untuk mewakili warna, encode karakter, dan banyak hal lain. Alaminya, ada cara lebih singkat menulis mereka: `0x`kemudian angkanya.
63
63
64
-
For instance:
64
+
Misalnya:
65
65
66
66
```js run
67
67
alert( 0xff ); // 255
68
-
alert( 0xFF ); // 255 (the same, case doesn't matter)
68
+
alert( 0xFF ); // 255 (sama, case diabaikan)
69
69
```
70
70
71
-
Binary and octal numeral systems are rarely used, but also supported using the`0b`and`0o` prefixes:
71
+
Sistem numeral binary dan octal jarang dipakai, tapi juga didukung menggunakan prefix`0b`dan`0o`:
72
72
73
73
74
74
```js run
75
-
let a =0b11111111; // binary form of 255
76
-
let b =0o377; // octal form of 255
75
+
let a =0b11111111; //bentuk binary dari 255
76
+
let b =0o377; //bentuk octal dari 255
77
77
78
-
alert( a == b ); // true, the same number 255 at both sides
78
+
alert( a == b ); // true, angka sama 255 dari kedua sisi
79
79
```
80
80
81
-
There are only 3 numeral systems with such support. For other numeral systems, we should use the function `parseInt` (which we will see later in this chapter).
81
+
Cuma ada 3 sistem numeral dengan dukungan begitu. Untuk sistem numeral lain, kita sebaiknya memakai fungsi `parseInt` (yang akan kita lihat nanti di bab ini).
82
82
83
83
## toString(base)
84
84
85
-
The method `num.toString(base)`returns a string representation of `num`in the numeral system with the given `base`.
85
+
Metode `num.toString(base)`mengembalikan representasi string dari `num`di sistem numeral dengan `base` yang diberikan.
86
86
87
-
For example:
87
+
Misalnya:
88
88
```js run
89
89
let num =255;
90
90
91
91
alert( num.toString(16) ); // ff
92
92
alert( num.toString(2) ); // 11111111
93
93
```
94
94
95
-
The `base`can vary from`2`to`36`. By default it's`10`.
-**base=16**is used for hex colors, character encodings etc, digits can be `0..9`or`A..F`.
100
-
-**base=2**is mostly for debugging bitwise operations, digits can be `0`or`1`.
101
-
-**base=36**is the maximum, digits can be `0..9`or`A..Z`. The whole latin alphabet is used to represent a number. A funny, but useful case for `36`is when we need to turn a long numeric identifier into something shorter, for example to make a short url. Can simply represent it in the numeral system with base`36`:
99
+
-**base=16**dipakai untuk warna hex, character encoding dll, digit bisa `0..9`atau`A..F`.
100
+
-**base=2**paling banyak untuk mendebug operasi bitwise, digit bisa `0`atau`1`.
101
+
-**base=36**ini maximum, digit bisa `0..9`atau`A..Z`. Seluruh alfabet latin dipakai untuk merepresentasi angka. Hal lucu, tapi berguna untuk `36`ialah saat kita harus mengubah identifier numerik panjang ke dalam sesuatu yang lebih pendek, misalnya untuk membuat url pendek. Bisa direpresentasikan dalam sistem`36`:
0 commit comments