Answers for "how to define optional parameter in typescript"

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

Code answers related to "how to define optional parameter in typescript"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language