Skip to content

Commit 2679ca4

Browse files
committed
fix(i18n): translate
1 parent 2bd0933 commit 2679ca4

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

1-js/02-first-steps/13-switch/article.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# The "switch" statement
1+
# Pernyataan "switch"
22

3-
A `switch` statement can replace multiple `if` checks.
3+
Pernyataan `switch` bisa mengganti pengecekan ganda `if`.
44

5-
It gives a more descriptive way to compare a value with multiple variants.
5+
Ia memberi cara lebih deskriptif untuk membandingkan nilai dengan varian ganda.
66

7-
## The syntax
7+
## Syntax
88

9-
The `switch` has one or more `case` blocks and an optional default.
9+
`switch` punya satu atau lebih blok `case` dan satu default opsional.
1010

11-
It looks like this:
11+
Rupanya seperti ini:
1212

1313
```js no-beautify
1414
switch(x) {
@@ -26,13 +26,13 @@ switch(x) {
2626
}
2727
```
2828

29-
- The value of `x` is checked for a strict equality to the value from the first `case` (that is, `value1`) then to the second (`value2`) and so on.
30-
- If the equality is found, `switch` starts to execute the code starting from the corresponding `case`, until the nearest `break` (or until the end of `switch`).
31-
- If no case is matched then the `default` code is executed (if it exists).
29+
- Nilai `x` dicek ekaulitasnya secara ketat dengan nilaid dari `case` pertama (yaitu, `value1`) lalu ke kedua (`value2`) dan seterusnya.
30+
- Jika ekualitas ditemukan, `switch` mulai mengexekusi kode mulai dari `case` yang berkorespondensi, hingga `break` terdekat (atau hingga akhir `switch`).
31+
- Jika tak ada case yang cocok maka kode `default` diexekusi (jika ada).
3232

33-
## An example
33+
## Contoh
3434

35-
An example of `switch` (the executed code is highlighted):
35+
Contoh `switch` (kode yang diexekusi dihighlight):
3636

3737
```js run
3838
let a = 2 + 2;
@@ -54,13 +54,13 @@ switch (a) {
5454
}
5555
```
5656

57-
Here the `switch` starts to compare `a` from the first `case` variant that is `3`. The match fails.
57+
Di sini `switch` mulai membandingkan `a` dari varian `case` pertama yang bernilai `3`. Kecocokan gagal.
5858

59-
Then `4`. That's a match, so the execution starts from `case 4` until the nearest `break`.
59+
Lalu `4`. Ada kecocokan, jadi exekusi mulai dari `case 4` hingga `break` terdekat.
6060

61-
**If there is no `break` then the execution continues with the next `case` without any checks.**
61+
**Jika tak ada `break` maka exekusi lanjut dengan `case` berikutnya tanpa pengecekan.**
6262

63-
An example without `break`:
63+
Contoh tanpa `break`:
6464

6565
```js run
6666
let a = 2 + 2;
@@ -79,18 +79,18 @@ switch (a) {
7979
}
8080
```
8181

82-
In the example above we'll see sequential execution of three `alert`s:
82+
Di contoh di atas kita akan lihat exekusi sekuensial dari tiga `alert`:
8383

8484
```js
8585
alert( 'Exactly!' );
8686
alert( 'Too big' );
8787
alert( "I don't know such values" );
8888
```
8989

90-
````smart header="Any expression can be a `switch/case` argument"
91-
Both `switch` and `case` allow arbitrary expressions.
90+
````smart header="Expresi apapun bisa berupa argumen `switch/case`"
91+
Baik `switch` maupun `case` membolehkan sembarang expresi.
9292

93-
For example:
93+
Misalnya:
9494

9595
```js run
9696
let a = "1";
@@ -107,14 +107,14 @@ switch (+a) {
107107
alert("this doesn't run");
108108
}
109109
```
110-
Here `+a` gives `1`, that's compared with `b + 1` in `case`, and the corresponding code is executed.
110+
Di sini `+a` memberikan `1`, yang dibandingkan dengan `b + 1` ndalam `case`, and the corresponding code is executed.
111111
````
112112
113-
## Grouping of "case"
113+
## Pengelompokan "case"
114114
115-
Several variants of `case` which share the same code can be grouped.
115+
Beberapa varian `case` yang berbagi kode yang sama bisa dikelompokkan.
116116
117-
For example, if we want the same code to run for `case 3` and `case 5`:
117+
Misalnya, jika kita ingin kode yang sama berjalan untuk `case 3` dan `case 5`:
118118
119119
```js run no-beautify
120120
let a = 2 + 2;
@@ -137,15 +137,15 @@ switch (a) {
137137
}
138138
```
139139
140-
Now both `3` and `5` show the same message.
140+
Sekarang baik `3` maupun `5` menampilkan pesan yang sama.
141141
142-
The ability to "group" cases is a side-effect of how `switch/case` works without `break`. Here the execution of `case 3` starts from the line `(*)` and goes through `case 5`, because there's no `break`.
142+
Kemampuan "mengelompokkan" case adalah efek samping dari bagaimana `switch/case` bekerja tanpa `break`. Di sini exekusi dari `case 3` mulai dari baris `(*)` dan tembus ke `case 5`, karena tidak ada `break`.
143143
144-
## Type matters
144+
## Tipe berpengaruh
145145
146-
Let's emphasize that the equality check is always strict. The values must be of the same type to match.
146+
Mari kita tekankan bahwa pengecekan ekualitas selalu ketat. Nilainya harus bertipe sama supaya cocok.
147147
148-
For example, let's consider the code:
148+
Misalnya, mari kita pertimbangkan kode ini:
149149
150150
```js run
151151
let arg = prompt("Enter a value?");
@@ -167,6 +167,6 @@ switch (arg) {
167167
}
168168
```
169169
170-
1. For `0`, `1`, the first `alert` runs.
171-
2. For `2` the second `alert` runs.
172-
3. But for `3`, the result of the `prompt` is a string `"3"`, which is not strictly equal `===` to the number `3`. So we've got a dead code in `case 3`! The `default` variant will execute.
170+
1. Untuk `0`, `1`, `alert` pertama berjalan.
171+
2. Untuk `2` `alert` kedua berjalan.
172+
3. Tapi untuk `3`, hasil dari `prompt` ialah string `"3"`, yang berbeda secara ketat `===` dengan angka `3`. Jadi kita punya kode mati di `case 3`! Varian `default` akan diexekusi.

0 commit comments

Comments
 (0)