Functions
What is it
Function Declaration
export function fnStatement(a: number, b: number): number { return a + b; }
Function Expression
const addNumbers = (a: number, b: number): number => a + b;
Breakdown
(): string
is areturn type
- Represents type of the
value
that is returned from a function
- Represents type of the
(param: int)
represents the parameters of the function, where the type is aninteger
Parameters
need their own typing
Optionals
// void return type function messageLogger(message: string): void { console.log(message); } // primitive return type function addNumbers(a: number, b: number): number { return a + b; } // Optional Parameter `y` function newFunc(x: number, y?: number) { ... } // Default Parameter function newFunc(name: string = "you"){ ... }