Sintaks Arrow

Tiga cara deklarasi function:

  • Deklarasi function;

  • Ekspresi function;

  • Simbol panah => ES6 (arrow sintaks)

contoh:

//deklarasi
function hello(){
    console.log("hello");
}

//ekspresi
const hello = function() {
    console.log("hello");
}

// panah/arrow function
const hello = () => {
    console.log("hello");
}

Perbedaan ES5 DAN ES6

//ES5
function tambah(a,b){
    return a+b;
}

//ES6
cons tambah = (a,b) => a + b;

Jadi tidak perlu sintaks return kalo di es6

Last updated

Was this helpful?