Skip to content

Commit dae1af3

Browse files
committed
feat(i18n): 1.02.15.article - つづく
1 parent d5844fc commit dae1af3

File tree

1 file changed

+40
-40
lines changed
  • 1-js/02-first-steps/15-function-expressions-arrows

1 file changed

+40
-40
lines changed

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

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
1-
# Function expressions and arrows
1+
# Expresi fungsi dan panah
22

3-
In JavaScript, a function is not a "magical language structure", but a special kind of value.
3+
Di JavaScript, fungsi bukan "struktur bahasa magis", melaikan satu bentuk nilai spesial.
44

5-
The syntax that we used before is called a *Function Declaration*:
5+
Syntax yang kita gunakan sebelumnya disebut *Deklarasi Fungsi*:
66

77
```js
88
function sayHi() {
99
alert( "Hello" );
1010
}
1111
```
1212

13-
There is another syntax for creating a function that is called a *Function Expression*.
13+
Ada syntax lain untuk membuat fungsi yang disebut *Expresi Fungsi*.
1414

15-
It looks like this:
15+
Rupanya seperti ini:
1616

1717
```js
1818
let sayHi = function() {
1919
alert( "Hello" );
2020
};
2121
```
2222

23-
Here, the function is created and assigned to the variable explicitly, like any other value. No matter how the function is defined, it's just a value stored in the variable `sayHi`.
23+
Di sini, fungsi dibuat dan diisi variabel secara explisit, seperti nilai lain manapun. Tak peduli bagaimana fungsi didefinisi, ia hanya suatu nilai yang disimpan dalam variabel `sayHi`.
2424

25-
The meaning of these code samples is the same: "create a function and put it into the variable `sayHi`".
25+
Arti dari sampel kode ini sama: "buatlah fungs dan taruhlah di dalam variabel `sayHi`".
2626

27-
We can even print out that value using `alert`:
27+
Kita bahkan bisa mencetak nilai itu menggunakan `alert`:
2828

2929
```js run
3030
function sayHi() {
3131
alert( "Hello" );
3232
}
3333

3434
*!*
35-
alert( sayHi ); // shows the function code
35+
alert( sayHi ); // menampilkan kode fungsi
3636
*/!*
3737
```
3838

39-
Please note that the last line does not run the function, because there are no parentheses after `sayHi`. There are programming languages where any mention of a function name causes its execution, but JavaScript is not like that.
39+
Tolong ingat bahwa baris terakhir tidak menjalankan fungsi, karena tak ada tanda kurung setelah `sayHi`. Ada bahasa pemrograman di mana satu penyebutan nama fungsi menyebabkan exekusi fungsi, tapi JavaScript tak seperti itu.
4040

41-
In JavaScript, a function is a value, so we can deal with it as a value. The code above shows its string representation, which is the source code.
41+
Di JavaScript, fungsi adalah nilai, jadi kita bisa menghadapinya sebagai nilai. Kode di atas menunjukkan representasi stringnya, yang mana kode sumbernya.
4242

43-
Surely, a function is a special values, in the sense that we can call it like `sayHi()`.
43+
Pastinya, fungsi adalah nilai spesial, dengan anggapan bahwa kita bisa memanggilnya seperti `sayHi()`.
4444

45-
But it's still a value. So we can work with it like with other kinds of values.
45+
Tapi ia tetaplah nilai. Jadi kita bisa memakainya seperti macam nilai lainnya.
4646

47-
We can copy a function to another variable:
47+
Kita bisa mengkopi fungsi ke variabel lain:
4848

4949
```js run no-beautify
50-
function sayHi() { // (1) create
50+
function sayHi() { // (1) buat
5151
alert( "Hello" );
5252
}
5353

54-
let func = sayHi; // (2) copy
54+
let func = sayHi; // (2) kopi
5555

56-
func(); // Hello // (3) run the copy (it works)!
57-
sayHi(); // Hello // this still works too (why wouldn't it)
56+
func(); // Hello // (3) jalankan kopinya (ia bekerja)!
57+
sayHi(); // Hello // ini juga masih bekerja (kenapa tidak)
5858
```
5959

60-
Here's what happens above in detail:
60+
Inilah yang terjadi di atas secara detil:
6161

62-
1. The Function Declaration `(1)` creates the function and puts it into the variable named `sayHi`.
63-
2. Line `(2)` copies it into the variable `func`. Please note again: there are no parentheses after `sayHi`. If there were, then `func = sayHi()` would write *the result of the call* `sayHi()` into `func`, not *the function* `sayHi` itself.
64-
3. Now the function can be called as both `sayHi()` and `func()`.
62+
1. Deklarasi Fungsi `(1)` membuat fungsi dan menaruhnya ke variabel bernama `sayHi`.
63+
2. Baris `(2)` mengkopinya ke variabel `func`. Tolong ingat lagi: tak ada tanda kurung setelah `sayHi`. Jika ada, maka `func = sayHi()` akan menulis *hasil panggilan* `sayHi()` ke `func`, bukan *fungsi* `sayHi` itu sendiri.
64+
3. Sekarang fungsi bisa dipanggil baik sebagai `sayHi()` maupun `func()`.
6565

66-
Note that we could also have used a Function Expression to declare `sayHi`, in the first line:
66+
Catat bahwa kita jusa bisa menggunakan Expresi Fungsi untuk mendeklarasi `sayHi`, di baris pertama:
6767

6868
```js
6969
let sayHi = function() {
@@ -74,11 +74,11 @@ let func = sayHi;
7474
// ...
7575
```
7676

77-
Everything would work the same.
77+
Semua akan berjalan sama.
7878

7979

80-
````smart header="Why is there a semicolon at the end?"
81-
You might wonder, why does Function Expression have a semicolon `;` at the end, but Function Declaration does not:
80+
````smart header="Kenapa ada semicolon di akhir?"
81+
Kamu mungkin penasaran, kenapa Expresi Fungsi punya semicolon `;` di akhir, tapi Deklarasi Fungsi tidak:
8282
8383
```js
8484
function sayHi() {
@@ -90,27 +90,27 @@ let sayHi = function() {
9090
}*!*;*/!*
9191
```
9292
93-
The answer is simple:
94-
- There's no need for `;` at the end of code blocks and syntax structures that use them like `if { ... }`, `for { }`, `function f { }` etc.
95-
- A Function Expression is used inside the statement: `let sayHi = ...;`, as a value. It's not a code block, but rather an assignment. The semicolon `;` is recommended at the end of statements, no matter what the value is. So the semicolon here is not related to the Function Expression itself, it just terminates the statement.
93+
Jawabannya simpel:
94+
- `;` tidak dibutuhkan di akhir blok kode dan struktur syntax yang memakai mereka seperti `if { ... }`, `for { }`, `function f { }` dll.
95+
- Expresi Fungsi digunakan di dalam pernyataan: `let sayHi = ...;`, sebagai nilai. Ia bukan blok kode, tapi lebih ke penetapan. Semicolon `;` disarankan di akhir pernyataan, tak peduli nilainya apa. Jadi semicolon di sini tak ada hubungannya dengan Expresi Fungsi itu sendiri, ia hanya menstop pernyataan.
9696
````
9797

98-
## Callback functions
98+
## Fungsi callback
9999

100-
Let's look at more examples of passing functions as values and using function expressions.
100+
Ayo kita lihat pada contoh lain mengoper fungsi sebagai nilai dan menggunakan expresi fungsi.
101101

102-
We'll write a function `ask(question, yes, no)` with three parameters:
102+
Kita akan menulis fungsi `ask(question, yes, no)` dengan tiga parameter:
103103

104104
`question`
105-
: Text of the question
105+
: Teks pertanyaan
106106

107107
`yes`
108-
: Function to run if the answer is "Yes"
108+
: Fungsi yang berjalan jika jawabannya "Yes"
109109

110110
`no`
111-
: Function to run if the answer is "No"
111+
: Fungsi yang berjalan jika jawabannya "No"
112112

113-
The function should ask the `question` and, depending on the user's answer, call `yes()` or `no()`:
113+
Fungsinya akan menanyakan `question` dan, tergantung jawabannya pengguna, panggil `yes()` atau `no()`:
114114

115115
```js run
116116
*!*
@@ -132,13 +132,13 @@ function showCancel() {
132132
ask("Do you agree?", showOk, showCancel);
133133
```
134134

135-
In practice, such functions are quite useful. The major difference between a real-life `ask` and the example above is that real-life functions use more complex ways to interact with the user than a simple `confirm`. In the browser, such function usually draws a nice-looking question window. But that's another story.
135+
Pada praktiknya, fungsi macam ini agak berguna. Perbedaan besar antara `ask` kehidupan-nyata dan contoh di atas adalah fungsi kehidupan-nyata memakai cara komplex untuk berinteraksi dengan pengguna daripada sekedar `confirm`. Di peramban, fungsi macam ini biasanya menarik window pertanyaan menarik. Tapi itu cerita lain lagi.
136136

137-
**The arguments `showOk` and `showCancel` of `ask` are called *callback functions* or just *callbacks*.**
137+
**Argumen `showOk` dan `showCancel` dari `ask` dipanggil *fungsi callback* atau hanya *callback*.**
138138

139-
The idea is that we pass a function and expect it to be "called back" later if necessary. In our case, `showOk` becomes the callback for "yes" answer, and `showCancel` for "no" answer.
139+
Idenya adalah kita mengoper fungsi dan berharap ia "dipanggil kembali" kemudian jika dibutuhkan. Pada kasus kita, `showOk` menjadi callback untuk jawaban "yes", dan `showCancel` untuk jawaban "no".
140140

141-
We can use Function Expressions to write the same function much shorter:
141+
Kita bisa memakai Expresi Fungsi untuk menulis fungsi yang sama lebih pendek:
142142

143143
```js run no-beautify
144144
function ask(question, yes, no) {

0 commit comments

Comments
 (0)