[JS] Function - 여러 인자

🍉effy·2021년 12월 29일
post-thumbnail


function meetAt(year, month, date) {
  if (date) {                    
    return `${year}/${month}/${date}`;
  } else if (month) {
    return `${year}년 ${month} 월`;
  } else (year); {
    return `${year}년`;
  }
}
console.log(meetAt(2021, 09));

✅if (date) 를 먼저 적은 이유 -> year 를 먼저 적으면 year 에서 조건문이 충족되기 때문에 다음 else if 로 안 넘어간다.

profile
Je vais l'essayer

0개의 댓글