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

# Dart Bitwise OR

The `|` operator in Dart serves as the bitwise inclusive OR operator for integers, a non-short-circuiting logical OR operator for booleans, and an overloadable operator for custom classes.

## Integer Bitwise OR

When applied to `int` operands, the `|` operator evaluates the binary representations of both operands position by position. If at least one of the corresponding bits is `1`, the resulting bit is `1`. If both bits are `0`, the resulting bit is `0`. The operation returns an `int`.

**Truth Table:**

* `0 | 0` yields `0`
* `0 | 1` yields `1`
* `1 | 0` yields `1`
* `1 | 1` yields `1`

**Platform Constraints:**

* **Dart Native (AOT/JIT):** Bitwise operations are performed on 64-bit two's complement integers.
* **Dart Web (compiled to JavaScript):** Bitwise operations are truncated to 32-bit integers to align with JavaScript's underlying bitwise semantics.

```dart theme={"dark"}
int a = 5; // Binary representation: ... 0101
int b = 3; // Binary representation: ... 0011

int result = a | b; 

print(result); // Outputs: 7 (Binary: ... 0111)
```

## Boolean Non-Short-Circuiting OR

When applied to `bool` operands, the `|` operator performs a logical OR operation returning a `bool`. Unlike the standard logical OR operator (`||`), the `|` operator does not short-circuit. It strictly evaluates both the left and right expressions regardless of whether the left expression evaluates to `true`.

```dart theme={"dark"}
bool evaluateRight() {
  print('Right evaluated');
  return true;
}

void main() {
  // 'evaluateRight()' is executed even though the left operand is true.
  bool result = true | evaluateRight(); 
}
```

## Operator Overloading

Dart supports operator overloading, allowing user-defined classes to implement the `|` operator. The parameter type and the return type are entirely dictated by the class definition.

```dart theme={"dark"}
class CustomValue {
  final int value;
  
  CustomValue(this.value);

  // Overriding the | operator
  CustomValue operator |(CustomValue other) {
    return CustomValue(this.value | other.value);
  }
}

void main() {
  CustomValue val1 = CustomValue(8);
  CustomValue val2 = CustomValue(4);
  
  CustomValue result = val1 | val2;
}
```

## Compound Assignment

The `|` operator can be combined with the assignment operator (`=`) to mutate a variable in place using the `|=` syntax. The variable being assigned to must be mutable (not `final` or `const`).

```dart theme={"dark"}
int value = 5;
value |= 3; // Strictly equivalent to: value = value | 3;

bool flag = false;
flag |= true; // Strictly equivalent to: flag = flag | true;
```

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