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/03-string/article.md
+32-32Lines changed: 32 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,17 +52,17 @@ Petik satu dan petik dua berasal dari masa lalu saat bahasa pemrograman dibuat,
52
52
53
53
Backtick juga memperbolehkan kita untuk menyediakan sebuah "fungsi template" sebelum backtick pertama. Sintaknya yaitu: <code>func`string`</code>. Fungsi `func` dipanggil secara otomatis, menerima string dan ekspresi yang berada di dalamnya, lalu dapat memproses mereka. Anda dapat membaca tentang fitur ini lebih lanjut di [dokumentasi](mdn:/JavaScript/Reference/Template_literals#Tagged_template_literals). Fitur ini dipanggil "tagged templates". Fitur ini mempermudah kita untuk membungkus string ke dalam template atau fungsionalitas lain, tetapi fitur ini jarang digunakan.
54
54
55
-
## Special characters
55
+
## Karakter-karakter spesial
56
56
57
-
It is still possible to create multiline strings with single and double quotes by using a so-called "newline character", written as `\n`, which denotes a line break:
57
+
Masih mungkin untuk membuat string dengan banyak baris menggunakan petik satu atau petik dua dengan menggunakan "karakter newline", ditulis seperti berikut `\n`, yang menandakan baris baru:
58
58
59
59
```js run
60
60
let guestList ="Guests:\n * John\n * Pete\n * Mary";
61
61
62
62
alert(guestList); // a multiline list of guests
63
63
```
64
64
65
-
For example, these two lines are equal, just written differently:
65
+
Sebagai contoh, kedua baris berikut sama saja, hanya ditulis dengan cara yang berbeda:
66
66
67
67
```js run
68
68
let str1 ="Hello\nWorld"; // two lines using a "newline symbol"
@@ -74,77 +74,77 @@ World`;
74
74
alert(str1 == str2); // true
75
75
```
76
76
77
-
There are other, less common "special" characters.
77
+
Ada karakter spesial yang lain, tetapi mereka lebih jarang digunakan
78
78
79
-
Here's the full list:
79
+
Berikut adalah daftar lengkapnya:
80
80
81
81
| Character | Description |
82
82
|-----------|-------------|
83
-
|`\n`|New line|
84
-
|`\r`|Carriage return: not used alone. Windows text files use a combination of two characters `\r\n`to represent a line break. |
85
-
|`\'`, `\"`|Quotes|
83
+
|`\n`|Baris baru|
84
+
|`\r`|Carriage return: tidak digunakan sendiri. File teks milik di Windows menggunakan kombinasi dari dua karakter `\r\n`untuk menandakan baris baru.|
85
+
|`\'`, `\"`|Petik-petik|
86
86
|`\\`|Backslash|
87
87
|`\t`|Tab|
88
-
|`\b`, `\f`, `\v`| Backspace, Form Feed, Vertical Tab -- kept for compatibility, not used nowadays. |
89
-
|`\xXX`|Unicode character with the given hexadecimal unicode `XX`, e.g.`'\x7A'`is the same as`'z'`.|
|`\u{X…XXXXXX}` (1 to 6 hex characters)|A unicode symbol with the given UTF-32 encoding. Some rare characters are encoded with two unicode symbols, taking 4 bytes. This way we can insert long codes. |
88
+
|`\b`, `\f`, `\v`| Backspace, Form Feed, Vertical Tab -- tetap bisa digunakan untuk kompabilitas, sekarang sudah tidak digunakan. |
89
+
|`\xXX`|Karakter unicode dengan nilai heksadesimal `XX`, misalnya`'\x7A'`itu sama saja dengan`'z'`.|
|`\u{X…XXXXXX}` (1 to 6 karakter heksadesimal)|Sebuah simbol unicode dengan encoding UTF-32. Beberapa karakter langka menggunakan dua simbol unicode, yang memakan 4 byte. Dengan cara ini kita dapat menggunakan kode yang panjang. |
alert( "\u{20331}" ); // 佫, a rare Chinese hieroglyph (long unicode)
98
98
alert( "\u{1F60D}" ); // 😍, a smiling face symbol (another long unicode)
99
99
```
100
100
101
-
All special characters start with a backslash character `\`. It is also called an "escape character".
101
+
Karakter-karakter spesial yang diawali dengan karakter backslash `\` kadang dipanggil dengan sebutan "escape character".
102
102
103
-
We might also use it if we wanted to insert a quote into the string.
103
+
Kita kadang dapat menggunakannya apabila kita ingin menggunakan petik di dalam string.
104
104
105
-
For instance:
105
+
Sebagai contoh:
106
106
107
107
```js run
108
108
alert( 'I*!*\'*/!*m the Walrus!' ); // *!*I'm*/!* the Walrus!
109
109
```
110
110
111
-
As you can see, we have to prepend the inner quote by the backslash `\'`, because otherwise it would indicate the string end.
111
+
Seperti yang kita lihat, kita harus menambahkan backslash di depan petik yang di dalam string `\'`, karena jika tidak petik tersebut akan menandakan akhir dari sebuah string.
112
112
113
-
Of course, only to the quotes that are the same as the enclosing ones need to be escaped. So, as a more elegant solution, we could switch to double quotes or backticks instead:
113
+
Tentu saja, hanya jenis petik yang sama dengan penutup string yang perlu di "escape". Jadi, solusi yang lebih elegan yaitu mengganti petik satu menjadi petik dua atau backtick:
114
114
115
115
```js run
116
116
alert( `I'm the Walrus!` ); // I'm the Walrus!
117
117
```
118
118
119
-
Note that the backslash `\`serves for the correct reading of the string by JavaScript, then disappears. The in-memory string has no`\`. You can clearly see that in `alert`from the examples above.
119
+
Ingat bahwa backslash `\`hanya dipakai untuk Javascript agar dapat membaca string dengan benar. Di dalam memori, string tidak memiliki`\`. Anda dapat melihatnya secara langsung pada contoh `alert`di atas.
120
120
121
-
But what if we need to show an actual backslash `\`within the string?
121
+
Tetapi bagaimana jika kita ingin menampilkan backslash `\`di dalam sebuah string?
122
122
123
-
That's possible, but we need to double it like`\\`:
123
+
Hal tersebut bisa dilakukan, tetapi kita harus menulisnya dua kali seperti ini`\\`:
124
124
125
125
```js run
126
126
alert( `The backslash: \\` ); // The backslash: \
127
127
```
128
128
129
-
## String length
129
+
## Panjang string
130
130
131
-
The`length`property has the string length:
131
+
Properti`length`memiliki panjang dari string:
132
132
133
133
```js run
134
134
alert( `My\n`.length ); // 3
135
135
```
136
136
137
-
Note that `\n`is a single "special" character, so the length is indeed`3`.
137
+
Perlu diingat bahwa `\n`adalah sebuah karakter spesial, jadi panjang dari string adalah`3`.
138
138
139
-
```warn header="`length`is a property"
140
-
People with a background in some other languages sometimes mistype by calling `str.length()`instead of just `str.length`. That doesn't work.
139
+
```warn header="`length`adalah sebuah properti"
140
+
Orang dengan latar belakang di bahasa pemrograman lain kadang salah mengetik `str.length()`alih-alih `str.length`. Hal tersebut tidak bekerja.
141
141
142
-
Please note that`str.length`is a numeric property, not a function. There is no need to add parenthesis after it.
142
+
Perlu diingat bahwa`str.length`adalah properti numerik, bukan sebuah fungsi. Tidak perlu menambahkan kurung di belakangnya.
143
143
```
144
144
145
-
## Accessing characters
145
+
## Mengakses karakter di dalam string
146
146
147
-
To get a character at position `pos`, use square brackets `[pos]` or call the method [str.charAt(pos)](mdn:js/String/charAt). The first character starts from the zero position:
147
+
Untuk mengakses karakter pada posisi `pos`, digunakan kurung kotak `[pos]` atau dengan method [str.charAt(pos)](mdn:js/String/charAt). Karakter pertama dimulai dari posisi ke-0:
148
148
149
149
```js run
150
150
let str = `Hello`;
@@ -157,9 +157,9 @@ alert( str.charAt(0) ); // H
157
157
alert( str[str.length - 1] ); // o
158
158
```
159
159
160
-
The square brackets are a modern way of getting a character, while`charAt`exists mostly for historical reasons.
160
+
Kurung kotak adalah cara modern untuk mengakses sebuah karakter, sementara`charAt`ada karena alasan historis.
161
161
162
-
The only difference between them is that if no character is found, `[]`returns`undefined`, and`charAt`returns an empty string:
162
+
Perbedaan satu-satunya di antara mereka adalah apabila tidak ada karakter yang ditemukan, `[]`mengembalikan`undefined`, dan`charAt`mengembalikan string kosong:
0 commit comments