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/02-first-steps/05-types/article.md
+79-79Lines changed: 79 additions & 79 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,57 +12,57 @@ Bahasa pemrograman yang memperbolehkan hal semacam ini dibsebut "dynamically typ
12
12
13
13
Ada tujuh tipe data dasar di JavaScript. Di sini, kita akan mengcover mereka secara umum dan di bab berikutnya kita akan berbicara tentang setiap dari mereka secara detil.
14
14
15
-
## Angka
15
+
## Number
16
16
17
17
```js
18
18
let n =123;
19
19
n =12.345;
20
20
```
21
21
22
-
Tipe *angka* merepresentasikan baik angka integer maupun floating point.
22
+
Tipe *number* merepresentasikan angka baik integer maupun floating point.
23
23
24
24
Ada banyak operasi untuk angka, misal perkalian `*`, pembagian `/`, penambahan `+`, pengurangan `-`, dan lainnya.
25
25
26
-
Besides regular numbers, there are so-called "special numeric values" which also belong to this data type: `Infinity`, `-Infinity`and`NaN`.
26
+
Selain angka reguler, ada yang disebut "nilai numerik spesial" yang juga bagian dari tipe data ini: `Infinity`, `-Infinity`dan`NaN`.
27
27
28
-
-`Infinity`represents the mathematical [Infinity](https://en.wikipedia.org/wiki/Infinity) ∞. It is a special value that's greater than any number.
28
+
-`Infinity`mewakili [Infinity](https://en.wikipedia.org/wiki/Infinity)matematis ∞. Ia merupakan nilai spesial yang lebih besar dari angka apapun.
29
29
30
-
We can get it as a result of division by zero:
30
+
Kita bisa mendapatkannya sebagai hasil dari pembagian oleh nol:
31
31
32
32
```js run
33
33
alert( 1/0 ); // Infinity
34
34
```
35
35
36
-
Or just reference it directly:
36
+
Atau langsung referensikan saja dia:
37
37
38
38
```js run
39
39
alert( Infinity ); // Infinity
40
40
```
41
-
-`NaN`represents a computational error. It is a result of an incorrect or an undefined mathematical operation, for instance:
41
+
-`NaN`mewakili errorkomputasional. Ia merupakan hasil operasi matematis yang salah atau tak-terdefinisi, misalnya:
42
42
43
43
```js run
44
-
alert( "not a number" / 2 ); // NaN, such division is erroneous
44
+
alert( "not a number" / 2 ); // NaN, pembagian macam ini keliru
45
45
```
46
46
47
-
`NaN`is sticky. Any further operation on`NaN`returns`NaN`:
47
+
`NaN`itu lengket. Operasi lanjutan apapun pada`NaN`menghasilkan`NaN`:
48
48
49
49
```js run
50
50
alert( "not a number" / 2 + 5 ); // NaN
51
51
```
52
52
53
-
So, if there's a `NaN` somewhere in a mathematical expression, it propagates to the whole result.
53
+
Jadi, jika ada `NaN`di manapun di expresi matematika, ia mempropagasi hasil keseluruhan.
54
54
55
-
```smart header="Mathematical operations are safe"
56
-
Doing maths is "safe" in JavaScript. We can do anything: divide by zero, treat non-numeric strings as numbers, etc.
55
+
```smart header="Operasi matematika itu aman"
56
+
Melakukan matematika itu "aman" dalam JavaScript. Kita bisa melakukan apapun: pembagian dengan nol, memperlakukan string non-numerik sebagai angka, dll.
57
57
58
-
The script will never stop with a fatal error ("die"). At worst, we'll get `NaN`as the result.
58
+
Script ini takkan pernah stop dengan fatal error ("die"). Paling buruk, kita akan mendapat `NaN`sebagai hasilnya.
59
59
```
60
60
61
-
Special numeric values formally belong to the "number" type. Of course they are not numbers in the common sense of this word.
61
+
Nilai numerik spesial formalnya merupakan bagian dari tipe "number". Tentu saja mereka bukan angka dalam pandangan umum dari kata ini.
62
62
63
-
We'll see more about working with numbers in the chapter<info:number>.
63
+
Kita akan melihat lebih tentang cara bekerja dengan angka di bab<info:number>.
64
64
65
-
## A string
65
+
## String
66
66
67
67
String di JavaScript harus dikelilingi petik.
68
68
@@ -78,89 +78,89 @@ Di JavaScript, ada 3 tipe petik.
78
78
2. Petik tunggal:`'Hello'`.
79
79
3. Backtick:<code>`Hello`</code>.
80
80
81
-
Double and single quotes are "simple" quotes. There's no difference between them in JavaScript.
81
+
Petik tunggal dan ganda merupakan petik "simpel". Tak ada perbedaan antara mereka di JavaScript.
82
82
83
-
Backticks are "extended functionality" quotes. They allow us to embed variables and expressions into a string by wrapping them in`${…}`, for example:
83
+
Backtick merupakan petik "fungsional lanjutan". Mereka memungkinkan kita mengembed variabel dan expresi ke dalam string dengan membungkus mereka dalam`${…}`, misalnya:
alert( `the result is *!*${1+2}*/!*` ); //the result is 3
91
+
//mengembed expresi
92
+
alert( `the result is *!*${1+2}*/!*` ); //hasilnya 3
93
93
```
94
94
95
-
The expression inside`${…}`is evaluated and the result becomes a part of the string. We can put anything in there: a variable like `name`or an arithmetical expression like `1 + 2`or something more complex.
95
+
Expresi di dalam`${…}`dievaluasi dan hasilnya menjadi bagian dari string. Kita bisa menaruh apapun di sana: variabel seperti `name`atau expresi aritmatika seperti `1 + 2`atau sesuatu yang lebih rumit.
96
96
97
-
Please note that this can only be done in backticks. Other quotes don't have this embedding functionality!
97
+
Tolong diingat bahwa ini hanya bisa dilakukan dalam backtick. Petik lain tidak punya fungsionalitas pengembedan!
98
98
```js run
99
-
alert( "the result is ${1 + 2}" ); //the result is ${1 + 2} (double quotes do nothing)
99
+
alert( "the result is ${1 + 2}" ); //hasilnya ${1 + 2} (petik ganda tak akan berpengaruh)
100
100
```
101
101
102
-
We'll cover strings more thoroughly in the chapter<info:string>.
102
+
Kita akan mengcover string lebih dalam di bab<info:string>.
103
103
104
-
```smart header="There is no *character* type."
105
-
In some languages, there is a special "character" type for a single character. For example, in the C language and in Java it is `char`.
104
+
```smart header="Tidak ada tipe *character*."
105
+
Dalam beberapa bahasa, ada tipe "character" spesial untuk karakter tunggal. Misalnya, di bahasa C dan di Java adalah `char`.
106
106
107
-
In JavaScript, there is no such type. There's only one type: `string`. A string may consist of only one character or many of them.
107
+
Di JavaScript, tak ada tipe semacam itu. Cuma ada satu tipe: `string`. String bisa berisi satu karakter atau lebih.
108
108
```
109
109
110
-
## A boolean (logical type)
110
+
## Boolean (tipe logika)
111
111
112
-
The boolean type has only two values: `true`and`false`.
112
+
Tipe boolean cuma punya dua nilai: `true`dan`false`.
113
113
114
-
This type is commonly used to store yes/no values: `true`means "yes, correct", and`false`means "no, incorrect".
114
+
Tipe ini umumnya digunakan untuk menyimpan niai ya/tidak: `true`artinya "ya, betul", dan`false`artinya "tidak, salah".
115
115
116
-
For instance:
116
+
Misalnya:
117
117
118
118
```js
119
-
let nameFieldChecked =true; //yes, name field is checked
120
-
let ageFieldChecked =false; //no, age field is not checked
119
+
let nameFieldChecked =true; //ya, field nama dicek
120
+
let ageFieldChecked =false; //tidak, field usia tak dicek
121
121
```
122
122
123
-
Boolean values also come as a result of comparisons:
123
+
Nilai boolean juga datang dari perbandingan:
124
124
125
125
```js run
126
126
let isGreater =4>1;
127
127
128
-
alert( isGreater ); //true (the comparison result is "yes")
128
+
alert( isGreater ); //benar (hasil perbandingan yaitu "ya")
129
129
```
130
130
131
-
We'll cover booleans more deeply in the chapter<info:logical-operators>.
131
+
Kita akan mengcover boolean lebih dalam di bab<info:logical-operators>.
132
132
133
-
## The "null" value
133
+
## Nilai "null"
134
134
135
-
The special `null`value does not belong to any of the types described above.
135
+
Nilai `null`spesial bukan bagian dari tipe apapun yang dijelaskan di atas.
136
136
137
-
It forms a separate type of its own which contains only the `null` value:
137
+
Ia membentuk tipe terpisah miliknya sendiri yang cuma berisi nilai `null`:
138
138
139
139
```js
140
140
let age =null;
141
141
```
142
142
143
-
In JavaScript, `null`is not a "reference to a non-existing object" or a "null pointer" like in some other languages.
143
+
Di JavaScript, `null`tidak "mereferensi ke objek yang tak ada" atau "null pointer" seperti beberapa bahasa lain.
144
144
145
-
It's just a special value which represents "nothing", "empty" or "value unknown".
145
+
Ia cuma nilai spesial yang mewakili "hampa", "kosong" atau "nilai tak-diketahui".
146
146
147
-
The code above states that`age`is unknown or empty for some reason.
147
+
Kode di atas menyatakan bahwa`age`tak diketahui atau kosong untuk beberapa alasan.
148
148
149
-
## The "undefined" value
149
+
## Nilai "undefined"
150
150
151
-
The special value `undefined`also stands apart. It makes a type of its own, just like`null`.
151
+
Nilai spesial `undefined`juga berbeda lagi. Ia punya tipe miliknya sendiri, sama seperti`null`.
152
152
153
-
The meaning of `undefined`is "value is not assigned".
153
+
Arti `undefined`ialah "nilai yang tak diassign".
154
154
155
-
If a variable is declared, but not assigned, then its value is`undefined`:
155
+
Jika variabel dideklarasi, namun tak diassign, maka nilainya`undefined`:
156
156
157
157
```js run
158
158
let x;
159
159
160
-
alert(x); //shows "undefined"
160
+
alert(x); //menampilkan "undefined"
161
161
```
162
162
163
-
Technically, it is possible to assign `undefined`to any variable:
163
+
Secara teknis, mungkin saja mengassign `undefined`ke variabel apapun:
164
164
165
165
```js run
166
166
let x =123;
@@ -170,28 +170,28 @@ x = undefined;
170
170
alert(x); // "undefined"
171
171
```
172
172
173
-
...But we don't recommend doing that. Normally, we use`null`to assign an "empty" or "unknown" value to a variable, and we use`undefined`for checks like seeing if a variable has been assigned.
173
+
...Tapi kita tidak menyarankan itu. Normalnya, kita gunakan`null`untuk mengassign nilai "kosong" atau "tak-diketahui" ke variabel, dan kita gunakan`undefined`untuk pengecekan seperti melihat apakah variabel telah diassign.
174
174
175
-
## Objects and Symbols
175
+
## Objek dan Simbol
176
176
177
-
The`object`type is special.
177
+
Tipe`object`itu special.
178
178
179
-
All other types are called "primitive" because their values can contain only a single thing (be it a string or a number or whatever). In contrast, objects are used to store collections of data and more complex entities. We'll deal with them later in the chapter <info:object>after we learn more about primitives.
179
+
Semua tipe lain disebut "primitive" karena nilainya bisa mengandung sesuatu yang tunggal (bisa jadi string atau angka atau apapun). Sebaliknya, objek digunakan untuk menyimpan koleksi data dan entitas lebih rumit. Kita akan berhadapan dengannya nanti di bab <info:object>setelah kita belajar tentang primitive.
180
180
181
-
The`symbol`type is used to create unique identifiers for objects. We have to mention it here for completeness, but it's better to study this type after objects.
181
+
Tipe`symbol`digunakan untuk membuat identifier unik untuk objek. Kita harus menyebutkannya demi kelengkapan, tapi lebih baik untuk belajar tipe ini setelah objek.
182
182
183
-
## The typeof operator[#type-typeof]
183
+
## Operator typeof [#type-typeof]
184
184
185
-
The`typeof`operator returns the type of the argument. It's useful when we want to process values of different types differently or just want to do a quick check.
185
+
Operator`typeof`mengembalikan tipe argumen. Berguna ketika kita ingin memproses nilai dari tipe berbeda secara berbeda atau cuma ingin mengecek sekilas.
186
186
187
-
It supports two forms of syntax:
187
+
Ia mendukung dua bentuk syntax:
188
188
189
-
1.As an operator: `typeof x`.
190
-
2.As a function: `typeof(x)`.
189
+
1.Sebagai operator: `typeof x`.
190
+
2.Sebagai fungsi: `typeof(x)`.
191
191
192
-
In other words, it works with parentheses or without them. The result is the same.
192
+
Dengan kata lain, ia berjalan dengan atau tanpa kurung. Hasilnya sama saja.
193
193
194
-
The call to `typeof x`returns a string with the type name:
194
+
Panggilan ke `typeof x`mengembalikan string dengan nama tipenya:
The last three lines may need additional explanation:
220
+
Tiga baris terakhir mungkin butuh penjelasan tambahan:
221
221
222
-
1.`Math`is a built-in object that provides mathematical operations. We will learn it in the chapter <info:number>. Here, it serves just as an example of an object.
223
-
2.The result of `typeof null`is`"object"`. That's wrong. It is an officially recognized error in`typeof`, kept for compatibility. Of course, `null`is not an object. It is a special value with a separate type of its own. So, again, this is an error in the language.
224
-
3.The result of `typeof alert`is`"function"`, because`alert`is a function of the language. We'll study functions in the next chapters where we'll see that there's no special "function" type in JavaScript. Functions belong to the object type. But`typeof`treats them differently. Formally, it's incorrect, but very convenient in practice.
222
+
1.`Math`ialah objek built-in yang menyediakan operasi matematik. Kita akan belajar itu di bab <info:number>. Di sini, itu cuma sekedar contoh dari objek.
223
+
2.Hasil `typeof null`yaitu`"object"`. Itu salah. Ini 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.
224
+
3.Hasil dari `typeof alert`yaitu`"function"`, karena`alert`merupakan fungsi dari bahasa. Kita akan belajar fungsi di bab berikutnya di mana kita akan melihat bahwa tak ada tipe "function" spesial di JavaScript. Fungsi merupakan bagian dari tipe objek. Tapi`typeof`memperlakukan mereka secara berbeda. Formalnya, itu salah, tapi sangat nyaman pada praktiknya.
225
225
226
226
227
-
## Summary
227
+
## Kesimpulan
228
228
229
-
There are 7 basic data types in JavaScript.
229
+
Ada 7 tipe data dasar dalam JavaScript.
230
230
231
-
-`number`for numbers of any kind: integer or floating-point.
232
-
-`string`for strings. A string may have one or more characters, there's no separate single-character type.
233
-
-`boolean`for`true`/`false`.
234
-
-`null`for unknown values -- a standalone type that has a single value`null`.
235
-
-`undefined`for unassigned values -- a standalone type that has a single value`undefined`.
236
-
-`object`for more complex data structures.
237
-
-`symbol`for unique identifiers.
231
+
-`number`untuk angka jenis manapun: integer atau floating-point.
232
+
-`string`untuk string. String mungkin punya satu atau lebih karakter, tak ada tipe katakter tunggal terpisah.
233
+
-`boolean`untuk`true`/`false`.
234
+
-`null`untuk nilai tak-diketahui -- tipe mandiri yang punya nilai tunggal`null`.
235
+
-`undefined`untuk nilai tak-diassign -- tipe mandiri yang punya nilai tunggal`undefined`.
236
+
-`object`untuk struktur data lebih rumit.
237
+
-`symbol`untuk identifier unik.
238
238
239
-
The`typeof`operator allows us to see which type is stored in a variable.
239
+
Operator`typeof`memungkinkan kita melihat tipe mana yang disimpan dalam variable.
240
240
241
-
-Two forms: `typeof x`or`typeof(x)`.
242
-
-Returns a string with the name of the type, like`"string"`.
243
-
-For`null`returns`"object"` -- this is an error in the language, it's not actually an object.
241
+
-Dua form: `typeof x`atau`typeof(x)`.
242
+
-Mengembalikan string dengan nama tipe, seperti`"string"`.
243
+
-Untuk`null`mengembalikan`"object"` -- ada error dalam bahasa, yang sebenarnya bukan objek.
244
244
245
-
In the next chapters, we'll concentrate on primitive values and once we're familiar with them, we'll move on to objects.
245
+
Di bab berikutnya, kita akan fokus pada nilai primitive dan sekali kita familiar dengan mereka, kita akan lanjut ke objek.
0 commit comments