Search⌘ K

Nullish Coalescing

Explore how TypeScript's nullish coalescing operator helps you manage default values for variables that may be null or undefined. Learn to apply this operator effectively for objects and primitive types to improve your code's reliability and reduce complexity.

Nullish coalescing for an object

TypeScript 3.7 brought the nullish coalescing operator: ??. On the left side of the operator is a variable or condition. On the right side is the result if the condition is null or undefined.

One use case for this operator is to check if a variable is set to define ...