> ## 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.

# JavaScript Logical OR

The logical OR (`||`) operator evaluates operands from left to right, returning the first truthy operand it encounters. If all operands evaluate to a falsy value, it returns the value of the final operand. Crucially, JavaScript's `||` operator returns the *actual uncoerced value* of the operand, not necessarily a boolean.

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

## Evaluation Mechanics

When evaluating `expr1 || expr2`, the JavaScript engine executes the following sequence:

1. Evaluates `expr1`.
2. Coerces the result of `expr1` to a boolean to determine its truthiness.
3. If the coerced value is `true` (truthy), the operator **short-circuits**. It immediately returns the uncoerced value of `expr1`, and `expr2` is never evaluated.
4. If the coerced value is `false` (falsy), the operator evaluates `expr2` and returns its uncoerced value.

## Truthy vs. Falsy

The behavior of `||` depends entirely on JavaScript's definition of falsy values. An operand is falsy if its evaluated value is one of the following:

* `false`
* `0`, `-0`, or `0n` (BigInt zero)
* `""`, `''`, or ` ` \`\` (empty strings)
* `null`
* `undefined`
* `NaN`

With the exception of `document.all` (a legacy web API quirk defined in the ECMAScript specification Annex B that evaluates to falsy), every other value in JavaScript—including empty arrays (`[]`) and empty objects (`{}`)—is truthy.

## Evaluation Examples

```javascript theme={"dark"}
// Returns the first truthy value
"hello" || "world"   // Returns "hello" (string)
0 || 42              // Returns 42 (number)
null || true         // Returns true (boolean)

// Returns the last value if all are falsy
false || 0           // Returns 0
undefined || null    // Returns null
"" || NaN            // Returns NaN
```

## Short-Circuiting Behavior

Because the operator stops evaluating as soon as it finds a truthy value, any expressions or side effects on the right-hand side of a truthy operand are completely ignored.

```javascript theme={"dark"}
// No ReferenceError is thrown because the right side is never reached
const a = true || someUndeclaredVariable; 

let x = 0;
const b = "truthy" || (x = 5); 
// b is "truthy". x remains 0 because the assignment is never evaluated.
```

## Chaining

When chaining multiple `||` operators, the engine evaluates sequentially from left to right, stopping at the exact moment a truthy value is resolved.

```javascript theme={"dark"}
const result = null || undefined || "first truthy" || "ignored";
// result is "first truthy"
```

## Operator Precedence

The `||` operator has a lower precedence than the logical AND (`&&`) operator. In expressions containing both, `&&` is evaluated first unless the order of operations is explicitly overridden using grouping parentheses `()`.

```javascript theme={"dark"}
// Evaluated as: true || (false && false)
true || false && false; // Returns true

// Evaluated as: (true || false) && false
(true || false) && false; // Returns false
```

## Contrast with Nullish Coalescing (`??`)

Because `||` short-circuits on *any* falsy value, it will bypass defined, non-nullish falsy values like `0`, `0n`, or `""`. To strictly check for nullish values (`null` or `undefined`) rather than all falsy values, modern JavaScript provides the Nullish Coalescing operator (`??`).

```javascript theme={"dark"}
// || bypasses the falsy 0, returning the right-hand operand
0 || 42; // Returns 42

// ?? only bypasses null or undefined, returning the left-hand operand
0 ?? 42; // Returns 0
```

<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 JavaScript 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>
