TypeScript : Functions : Default Parameters


I want a parameter to have a default value in my TypeScript function.


You can assign a value to a parameter in your parameter list. The value can be any type of object and even functions.


MyFunction(myString: string, myDefaultValue = "This is a string": string) { ... }

MyFunction(myNumber: number, myDefaultValue = getDefaultValue(): any) {...} //could be : string, or anything else