A union-typed value may have several shapes. A check such as typeof narrows the possible type within a branch.
The demo alternates a string and a number in one variable. A real JavaScript check runs uppercase conversion for the string and decimal formatting for the number. Calling a type-specific method outside the checked branch can fail.
When to use
Use narrowing when handling values that may have different types, such as API responses or user input.