## 매개변수:함수 선언에서 활용하기 위하여 사용하는 변수
function getMaxNum( ){ }
parameter를 어떻게 지정을 해줘야 할까요??
function getMaxNum(...nums){ consoloe.log(nums); //[3,5,8,10] } getMaxNum(3,5,8,10);
'...'+ '변수' = 'Rest Parameter'를 이용해 매개변수로 지정해준다!
function getMaxNum(){ console.log(arguments); //{0:3, 1:5, 2:8, 3:10} } getMaxNum(3,5,8,10);
arguments 라는 키워드사용하기!
✓ arguments 객체는 배열같아 보이지만 배열이 아닌
유사배열
이다
arguments[0]; //3 arguments[1]; //5 arguments[2]; //8 arguments[3]; //10 arguments.forEach //undefined;
function getRoute(destination, departure = 'ICN'){ return '출발지: ' + departure + ',' + '도착지: ' + destination; } getRoute('PEK'); // '출발지: ICN, 도착지: PEK
중간에 기본 매개변수가 들어가는 경우, undefined를 넘겨줬을 때 기본값으로 처리한다.
function getRoute(departure = 'ICN' , destination){ return '출발지: ' + departure + ',' + '도착지: ' + destination; } getRoute(undefined ,'PEK'); // '출발지: ICN, 도착지: PEK