function이라는 키워드를 사용하지않고 화살표를 쓴다.

 

기본식

// ES5
function () {}

// ES6
() => {}
//ES5 함수 정의
var fn = function(a, b) {
 return a + b;
};

//ES6 함수 정의
let sum = (a, b) => {
 return a + b;
}

sum(10, 20);

배열 반복문 비교

// ES5 반복문
var arr = ["a", "b", "c"];
arr.forEach(function(value) {
 console.log(value); // a, b, c
});

// ES6 반복문
let arr = ["a", "b", "c"];
arr.forEach(value => console.log(value)); // a, b, c

+ Recent posts