TypeScript
[Typescript] 선택적 매개변수 사용 방법 - 매개변수 뒤에 물음표
SunPark
2021. 6. 23. 23:14
함수의 매개변수에 물음표를 붙임으로써 매개변수를 선택적으로 사용
// case 1
function hi(a: string, b?: string) {
console.log(a, b);
}
add("hello", "world!") // hello world!
add("hello") // hello undefined
// case 2
const hi => (a: string, b?: string) {
console.log(a, b);
}
add("hello", "world!") // hello world!
add("hello") // hello undefined
반응형