analogcoding

arrow function 예시 본문

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)

 

'Study JS for me > Keyword' 카테고리의 다른 글

Destructuring  (0) 2019.05.14
arrow function 의 this context  (0) 2019.05.14
Object property  (0) 2019.05.13
spread operator / rest parameter  (0) 2019.05.13
Arrow function  (0) 2019.05.11
Comments