Write typed functions with parameters and return types.
TypeScript lets you annotate both parameter types and the return type.
function add(a: number, b: number): number {
return a + b;
}
const multiply = (a: number, b: number): number => a * b;
TypeScript will warn you if you pass the wrong types or return the wrong value.
Add ? to make a parameter optional:
function greet(name?: string): string {
return `Hello, ${name ?? 'stranger'}!`;
}
Write and export a function named add that:
number parameters: a and bnumberexport function add(a: number, b: number): number {
// your code here
}
// Write and export a function named 'add' // that takes two numbers and returns their sum