Answers for "typescript optional parameters"

15

typescript optional parameters

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

sayHello(); // Prints 'undefined'

sayHello('world'); // Prints 'world'
Posted by: Guest on July-21-2020
4

typescript optional parameters

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

sayHello(); // Prints 'hello'

sayHello('world'); // Prints 'world'
Posted by: Guest on July-21-2020
1

how to define optional parameter in typescript

function functionName(par1: number, par2?: number) {

}
Posted by: Guest on May-18-2021
1

how to make a parameter optional in typescript

// Optional parameter
function foo(x?: number) {
    console.log("x : "+ x);
}
foo();
foo(6);
Posted by: Guest on January-24-2021
0

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;
}
Posted by: Guest on January-05-2021
0

typescript optional parameters

ka.shif7654
Posted by: Guest on September-24-2021

Code answers related to "typescript optional parameters"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language