default value to parameter in typescript funcion code example
Example 1: how to make a parameter optional in typescript
// Optional parameter
function foo(x?: number) {
console.log("x : "+ x);
}
foo();
foo(6);
Example 2: typescript default parameter
function sayName({ first, last = 'Smith' }: {first: string; last?: string }): void {
const name = first + ' ' + last;
console.log(name);
}
sayName({ first: 'Bob' });