[JavaScript] Arrow Function

dev_sang·2021년 10월 8일
0

JavaScript

목록 보기
1/11
post-thumbnail

Arrow Function

  • '화살표 함수'
  • 기존 funciton함수 선언 보다 훨씬 짧게 작성 가능한 표현방식
  • function이라는 키워드를 생략
  • 바로 괄호 안에 매개변수 받은 뒤 => 를 써주고 중괄호를 열어 코드 작성

예시: x, y 값 받아서 콘솔창에 출력하기

기존 함수

const example1 = function(x, y) {
	console.log(x, y);
};

또는

function example1(x, y) {
	console.log(x, y);
};

화살표 함수!!

const example2 = (x,y) => {
  	console.log(x,y); 
};

// 함수 호출
example(6, 8)
  • 위와 같이 return값만 있는 짧은 함수의 경우 중괄호와 return도 생략하고 바로 return값을 입력할 수 있다
const example3 = (x, y) => console.log(x, y);

// 함수호출
example2(7,8);
profile
There is no reason for not trying.

0개의 댓글