TypeScript默認參數
function test (a : string, b: string, c : string = "abc" ) {
console.log(a)
console.log(b)
console.log(c)
}
test("aaa","bbb") // 執行結果 aaa, bbb, abc c中的值為方法的默認值abc 注:使用默認值參數的時候必須放在參數的最后一位
TypeScript可選參數
function test (a : string, b?: string, c : string = "abc" ) {
console.log(a)
console.log(b)
console.log(c)
}
test("aaa") // 執行結果 aaa, undefined, abc 注:可選參數必須聲明在必須參數之后
