Thuta Learning
IntermediateProgrammingintermediate

Functions

Relax. We'll talk through this in plain words — no textbook voice.

You can specify types for a function's parameters and return value. This ensures the function is used correctly.

typescript
// This function takes two numbers and returns a number
function add(a: number, b: number): number {
  return a + b;
}

// This function doesn't return anything (void)
function logMessage(message: string): void {
  console.log(message);
}

let sum: number = add(5, 10);
logMessage("The sum is " + sum);
You should see
The sum is 15
Functions | Thuta Learning