TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
?? (nullish coalescing) operator is a logical operator that evaluates and returns its right-hand operand strictly when its left-hand operand is null or undefined (collectively termed “nullish”). If the left-hand operand is any other value, the operator returns the left-hand operand.
Nullish vs. Falsy Evaluation
The primary mechanical distinction of?? is its strict adherence to nullish values, contrasting with the logical OR (||) operator, which triggers on any falsy value (e.g., 0, "", NaN, false). The ?? operator preserves valid falsy primitives that would otherwise be overridden by ||.
Short-Circuit Evaluation
The?? operator implements short-circuiting. The right-hand expression is only evaluated if the left-hand operand resolves to null or undefined. If the left-hand operand is non-nullish, the right-hand execution is entirely bypassed.
Operator Precedence and Chaining
The?? operator has a lower precedence than || and &&. To prevent ambiguous evaluation logic, TypeScript and modern JavaScript engines throw a SyntaxError if ?? is chained directly with && or || without explicit grouping.
Type Narrowing
In TypeScript’s type system, the?? operator automatically narrows the inferred type of the resulting expression by excluding null and undefined from the left operand’s type union, provided the right operand does not also include them.
Master TypeScript with Deep Grasping Methodology!Learn More





