> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript Logical OR

The logical OR (`||`) operator evaluates operands from left to right and returns the first truthy operand it encounters. If all operands evaluate to falsy values, it returns the value of the last operand. It utilizes short-circuit evaluation, meaning the runtime bypasses the evaluation of subsequent operands immediately after a truthy value is resolved.

```typescript theme={"dark"}
expr1 || expr2
```

## Evaluation Mechanics

The operator relies on JavaScript's underlying boolean coercion rules. The following values are strictly evaluated as falsy: `false`, `0`, `-0`, `0n`, `""` (empty string), `null`, `undefined`, and `NaN`. All other values are evaluated as truthy.

1. If `expr1` can be coerced to `true` (truthy), the expression returns `expr1`. `expr2` is never evaluated.
2. If `expr1` can be coerced to `false` (falsy), the expression evaluates and returns `expr2`.

## TypeScript Type Resolution

At compile time, TypeScript infers the return type of a `||` expression as a union of the types of its operands.

```typescript theme={"dark"}
declare const leftOperand: string;
declare const rightOperand: number;

// Inferred type: string | number
const result = leftOperand || rightOperand; 
```

## Control Flow Analysis and Type Narrowing

TypeScript's compiler uses the `||` operator to perform control flow analysis and type narrowing. When the `||` operator is evaluated, TypeScript automatically removes types known to be falsy (such as `null` or `undefined`) from the resulting type union, provided the right-hand operand does not also contain those types.

```typescript theme={"dark"}
declare const maybeString: string | null | undefined;
declare const definiteString: string;

// Inferred type: string
// TypeScript removes 'null' and 'undefined' from the union 
// because they are falsy and force the evaluation of definiteString.
const resolved = maybeString || definiteString;
```

If the left operand contains literal types that are falsy (e.g., `""` or `0`), TypeScript will also exclude those specific literal types from the left side of the resulting union.

```typescript theme={"dark"}
declare const count: 0 | 1 | 2;
declare const fallback: 100;

// Inferred type: 1 | 2 | 100
// The literal '0' is falsy, so it is stripped from the left operand's contribution.
const finalCount = count || fallback;
```

## Operator Chaining

Multiple `||` operators can be chained sequentially. The short-circuit evaluation remains strictly left-to-right, and the TypeScript compiler expands the union type to include all potential return values across the chain.

```typescript theme={"dark"}
expr1 || expr2 || expr3
```

```typescript theme={"dark"}
declare const a: boolean | undefined;
declare const b: string | null;
declare const c: number;

// Inferred type: true | string | number
// 'false', 'undefined', and 'null' are stripped during left-to-right narrowing.
const chainedResult = a || b || c;
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor TypeScript Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
