ECMA Script는 JavaScript를 표준화한 것을 말한다.
function(){}
() => {}
<script> function getname(){} const getname = () => {} const getname = function(){} </script>
<script> function getname(name){} const getname = (name) => {} const getname = name => {} const getname = (name, age) => {} </script>
- 인자가 하나일 때는 소괄호 생략이 가능.
- 인자가 두 개일 때는 생략할 수 없다.
<script> function hi(text) { text += '하세요'; return text; } const hi = text => { text += '하세요'; return text; } </script>
<script> function getName(name) { return name; } const getName = name => { return name; } const getName = name => name; </script>
- 함수가 실행내용이 딱히 없이 return만 한다면 return 키워드와 중괄호가 생략이 가능하다.
- 중괄호와 return문이 생략될 경우, 화살표 오른쪽에는 리턴될 "값"만 쓰여야 한다. 다른 코드가 들어가면 안됨!
<script> function getFullName(first, family) { return first + family; } const getFullName = (first, family) => { return first + family }; const getFullName = (first, family) => first + family; </script>