0Pricing
TypeScript Academy · Lesson

Optional and Default Parameters

Handle missing arguments with ? and default values.

Welcome

TypeScript lets you mark function parameters as optional with `?` or give them default values. This makes APIs flexible while staying type-safe.

Optional Parameters with ?

Add `?` after a parameter name to make it optional. The parameter type becomes T | undefined inside the function.
function greet(name: string, greeting?: string): string {
  return (greeting ?? 'Hello') + ', ' + name;
}

All lessons in this course

  1. Parameter and Return Type Annotations
  2. Optional and Default Parameters
  3. Rest Parameters and Spread with Types
  4. void, never, and Function Signatures
← Back to TypeScript Academy