DEV Community 👩‍💻👨‍💻

DEV Community 👩‍💻👨‍💻 is a community of 964,423 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Ali Nurdin
Ali Nurdin

Posted on

Arrow Function di Javascript

Pada Javascript, arrow function adalah sebuah mekanisme pembuatan function expression tanpa harus menuliskan keyword 'function'.
Berikut contoh arrow function:

let greet = () => console.log('halo')
// menjalankan function greet
greet()
Enter fullscreen mode Exit fullscreen mode

Keistimewaan lainnya dari arrow function yaitu adanya implicit return.
Implicit return adalah sebuah cara sebuah arrow function mengembalikan nilai tanpa harus menuliskan keyword 'return'.
Contoh implicit return:

let multiple = (number1, number2) => number1 * number2
console.log(multiple(10, 20))
Enter fullscreen mode Exit fullscreen mode

Implicit return ini hanya berlaku jika arrow function ditulis dengan satu baris saja. Kalau muli line, maka harus secara explisit dituliskan keyword 'return'-nya

let multiple = (number1, number2) => {
   return number1 * number2
}
console.log(multiple(10, 20))
Enter fullscreen mode Exit fullscreen mode

berikut penjelasan singkat tentang arrow function di Javascript, terima kasih sudah membaca artikel ini.

Top comments (0)

In defense of the modern web

I expect I'll annoy everyone with this post: the anti-JavaScript crusaders, justly aghast at how much of the stuff we slather onto modern websites; the people arguing the web is a broken platform for interactive applications anyway and we should start over;

React users; the old guard with their artisanal JS and hand authored HTML; and Tom MacWright, someone I've admired from afar since I first became aware of his work on Mapbox many years ago. But I guess that's the price of having opinions.