Lesson 7 of 56
TypescriptFunctions – Parameter & Return Types
20 minutes
Course progress13%
Function Signatures
function add(a: number, b: number): number {
return a + b;
}
The compiler checks both parameter and types.
Lesson 7 of 56
Typescript20 minutes
function add(a: number, b: number): number {
return a + b;
}
The compiler checks both parameter and types.
?)function greet(name?: string): string {
return name ? `Hello, ${name}` : "Hello!";
}
function multiply(a: number, b: number = 2): number {
return a * b;
}
...)function sum(...values: number[]): number {
return values.reduce((a, b) => a + b, 0);
}
function log(msg: string): void {
console.log(msg);
// implicit return of undefined
}