Union types allow a value to be one of several types (e.g., string | number). Use them when a value can legitimately have multiple types.
Expanding on the short answer — what usually matters in practice:
A tiny example (an explanation template):
// Example: discuss trade-offs for "what-are-union-types-and-when-do-you-use-them?"
function explain() {
// Start from the core idea:
// Union types allow a value to be one of several types (e.g., string | number). Use them whe
}