Bootstrap

typeScript基础(3)_ts函数默认值和可选参数

ts函数默认值

//函数默认值
const fun = (num1: number = 12, num2: number = 24): number => {
    return num1 + num2
}
fun()

ts函数可选参数

//函数默认值
const fun = (num1: number = 12, num2?: number ): number => {
    return num1 + num2 ? num2 : 0
}
fun()
;