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

The `|=` operator is a compound assignment operator in Dart that performs an OR (`|`) operation between the left and right operands and assigns the resulting value back to the left operand. Its behavior is dictated by the implementation of `operator |` on the left operand's type.

```dart theme={"dark"}
a |= b;
```

While conceptually similar to `a = a | b;`, the compound assignment operator evaluates the left-hand side expression **exactly once**. This is a critical semantic distinction if the left operand is an expression with side effects, such as a mutating indexer or a function call. In a compound assignment, the side effect is triggered only once, whereas the expanded form would evaluate it twice.

```dart theme={"dark"}
// The index 'i' is incremented exactly once.
list[i++] |= b; 

// In contrast, the expanded form increments 'i' twice:
// list[i++] = list[i++] | b;
```

## Built-in Type Mechanics

**Integers (`int`) and `BigInt` (Bitwise OR)**
When applied to `int` or `BigInt` types, the operator performs a bitwise OR. It evaluates the binary representation of both operands, returning `1` for each bit position where at least one of the corresponding bits is `1`. If both bits are `0`, the resulting bit is `0`.

*Platform-Specific Behavior for `int`:*

* **Native Dart (Dart VM):** Bitwise operations are evaluated as 64-bit integers.
* **Web Dart (Compiled to JavaScript):** Bitwise operations truncate the operands to 32-bit integers prior to evaluation.

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

a |= b;     // Performs: 0101 | 0011
print(a);   // Outputs: 7 (Binary: ...0111)
```

**Booleans (`bool`) (Non-Short-Circuiting Logical OR)**
When applied to `bool` types, `|=` invokes Dart's non-short-circuiting logical OR (`|`). Unlike the standard `||` operator, which stops evaluation if the left operand is `true`, the `|` operator evaluates both the left and right operands. It assigns `true` to the left operand if at least one of the evaluated values is `true`.

```dart theme={"dark"}
bool a = false;
bool b = true;

a |= b; 
print(a);   // Outputs: true
```

## Custom Types and Operator Overloading

Because Dart supports operator overloading, the `|=` operator is not restricted to primitive types. Any custom class can implement `operator |`, which automatically enables the `|=` compound assignment operator for instances of that class.

For the assignment to be valid, the right operand must be of a type accepted by the left operand's `operator |` signature, and the resulting return type must be assignable back to the left operand's variable type.

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

  // Overriding the | operator automatically enables |=
  BitMask operator |(BitMask other) {
    return BitMask(this.value | other.value);
  }
}

void main() {
  BitMask mask1 = BitMask(4); // Binary: 0100
  BitMask mask2 = BitMask(2); // Binary: 0010

  mask1 |= mask2; 
  
  print(mask1.value); // Outputs: 6 (Binary: 0110)
}
```

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