export function twoFer(param: int): string { ... }
(): string
is called a return type
(param: int)
represents the parameters for the function
export
allows the test to import the function and call it
// Optional Parameter `y` function newFunc(x: number, y?: number) { ... } // Default Parameter function newFunc(name: string = "you"){ ... } function applyDiscount(price: number, discount: number = 0.05): number { return price * (1 - discount); } console.log(applyDiscount(100)); // 95
// void return type function messageLogger(message: string): void { console.log(message); } // primitive return type function addNumbers(a: number, b: number): number { return a + b; }
Function Expression with number
return type
const addNumbers = (a: number, b: number): number => a + b;