可选参数 要写在 必选参数 的后面
代码里要对可选参数为undefined时做处理
function test(a: string, b?: string, c: string = "Jack") {
console.log(a);
console.log(b);
console.log(c);
}
test("xxx")
输出
xxx
undefined
Jack
可选参数 要写在 必选参数 的后面
代码里要对可选参数为undefined时做处理
function test(a: string, b?: string, c: string = "Jack") {
console.log(a);
console.log(b);
console.log(c);
}
test("xxx")
输出
xxx
undefined
Jack