Develop Dairy/JavaScript, React

Arrow function (ES6 Extension)

개발자_옹이양 2019. 1. 16. 08:12

훨씬 보기좋은 ES6 문법 arrow function

const handleListening = function handleListening(req,res){
console.log(`Listening on: http://localhost:${PORT}`);
}


const handleHome = function handleHome(req, res){
console.log(req);
res.send("Hello from home");
}


↓로 바꿀 수 있다.


const handleListening = (req, res) => console.log(`Listening on: http://localhost:${PORT}`);


const handleHome = (req, res) => {
console.log(req);
res.send("Hello from home");
}


=> 이런 표현을 볼 수 있는데 Arrow function 이라고 한다. 훨씬 보기좋아졌다.



arrow function에서 무언가를 리턴하고 싶다면

와같은 함수를 아래같이바꾼다


true를 리턴한다라는 뜻이된다. 위와같은 뜻이되어버림



하지만

{} 대괄호를 적어주면 암시적 성격을 잃게 되어서 return을 적어줘야한다.


lala = () => {
return true
}





'Develop Dairy > JavaScript, React' 카테고리의 다른 글

Middlewares 익스프레스의 미들웨어의 이해  (0) 2019.01.19
nodemon package in NodeJS  (0) 2019.01.16
Use Babel in nodeJS  (0) 2019.01.16
Handling Express  (0) 2019.01.15
Start Express Sever  (0) 2019.01.15