Union & Literal Types
Giving a variable multiple types (|) and allowing only specific values (literal).
Simple enough for a 5-year-old to understand
Union type ( | )
With |, you state that a variable can be one of several types.
let identity: number | string;identity = 42;console.log(identity);identity = "A42";console.log(identity);🎯 Exercise & Practice
Test what you've learned — answer, write code, check instantly. (1 left)