Study JS for me/Keyword

arrow function 예시

be well 2019. 5. 14. 15:55
let arr = [1,2,3,4].map(function(v){
return v * 2;
});
ES5

let arr2 = [1,2,3,4].map( (v)=>{
 return v * 2;
})
ES6

let arr2 = [1,2,3,4].map( (v) =>( v * 2))
축약​

기존 function 보다 짧게 , 가독성 있게 사용할 수 있다.

ES6 이전

setTimeOut(function(){
  console.log('hello')
},1000)

ES6 arrow function

setTimeOut( ()=>{
  console.log('arrow');
},1000)