optional parameter in ts code example

Example 1: typescript optional parameters

// Optional Parameters
sayHello(hello?: string) {
	console.log(hello);
}

sayHello(); // Prints 'undefined'

sayHello('world'); // Prints 'world'

Example 2: typescript default parameter

// Default Parameters
sayHello(hello: string = 'hello') { 
    console.log(hello); 
}

sayHello(); // Prints 'hello'

sayHello('world'); // Prints 'world'

Example 3: typescript make function argument optional

function multiply(a: number, b: number, c?: number): number {

    if (typeof c !== 'undefined') {
        return a * b * c;
    }
    return a * b;
}