HomeToolsAbout

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 a return type
    • Represents type of the value that is returned from a function
  • (param: int) represents the parameters of the function, where the type is an integer
    • 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"){ ... }
AboutContact