function age(birthYear) {
return 2023 - birthYear;
}
const myAge = age(1900);
const age = function (birthYear) {
return 2023 - birthYear;
}
const myAge = age(1900);
// 선언 전 사용 예시
const myAge = age(1900);
const age = function (birthYear) {
return 2023 - birthYear;
}
// 코드 실행 순서
const myAge;
const age;
// age변수는 아직 함수가 아니기 때문에 age is not a function이라는 error가 발생한다.
myAge = age(1900);
age = function (birthYear) {
return 2023 - birthYear;
}
const calcAge3 = birthYear => 2037 - birthYear;
const yearsUntilRetirement = (birthYear, firstName) => {
const age = 2037 - birthYear;
const retirement = 65 - age;
return `${firstName} retires in ${retirement} years`
}
undefined
를 설정해주면 된다.const bookings = [];
const createBooking = (flightNum, numPassengers = 1, price = 199 * numPassengers) => {
const booking = {
flightNum,
numPassengers,
price
}
bookings.push(booking);
};
createBooking('LH123');
createBooking('LH1234', undefined, 1000);
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Functions/Default_parameters
https://poiemaweb.com/js-function
https://poiemaweb.com/es6-arrow-function
https://www.udemy.com/course/the-complete-javascript-course/