[S4] 함수
https://github.com/OneMoreBottlee/TypeScript-Master/tree/main/S4
매개변수 애너테이션 설정
const square = (num : number) => {
return num * num
}// 변수별 설정 가능
const doSomething = (person: string, age: number, isFunny: boolean) => {};
// 초기값 설정 가능
function greett(person: string = "stranger"){
return `Hi there, ${person}!`
}반환값에 애너테이션 설정
function square2(num: number):number {
return num * num;
}
square(2)
// 리턴값의 타입이 다양할수도 있음
// 문자열일수도, 숫자일수도 있음
function rand(num: number) {
if(Math.random() < 0.5) {
return num.toString()
}
return num
}
rand(3)익명함수
Void
Never
Last updated