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

The `|=` (bitwise OR assignment) operator performs a bitwise OR operation between the binary representations of its left and right operands, assigning the resulting value to the left operand.

## Syntax

```typescript theme={"dark"}
x |= y;
```

This is syntactically equivalent to:

```typescript theme={"dark"}
x = x | y;
```

## Mechanics

1. **Operand Conversion:**
   * For `number` types, TypeScript (following JavaScript semantics) implicitly truncates both operands into 32-bit signed integers represented in two's complement format.
   * For `bigint` types, operands are not truncated to 32 bits and retain their arbitrary precision during the bitwise operation.
2. **Bitwise Evaluation:** The operator compares the operands bit by bit. If either the left bit *or* the right bit at a given position is `1`, the corresponding bit in the result is set to `1`. It yields `0` only if both bits are `0`.
3. **Assignment:** The evaluated result is assigned back to the left operand. For `number` types, the 32-bit integer result is converted back into a standard IEEE 754 double-precision float before assignment.

## Truth Table

\| Bit `x` | Bit `y` | Result (`x | y`) |
\| :---: | :---: | :---: |
\| 0 | 0 | **0** |
\| 0 | 1 | **1** |
\| 1 | 0 | **1** |
\| 1 | 1 | **1** |

## Code Visualization

```typescript theme={"dark"}
let a: number = 5;  
// 32-bit binary: 00000000000000000000000000000101

let b: number = 3;  
// 32-bit binary: 00000000000000000000000000000011

a |= b;             
// Bitwise OR:    00000000000000000000000000000111
// Decimal value: 7

console.log(a); // 7
```

## TypeScript Type Constraints

TypeScript enforces strict type checking on bitwise operators to prevent unintended runtime coercion:

* **Valid Numeric Types:** Operands must be of a valid numeric type (`number`, `bigint`, or an `enum`). Attempting to use `|=` with strictly typed non-numeric types (such as `string`, `boolean`, or `object`) will trigger compiler error `TS2362` (for the left-hand side) or `TS2363` (for the right-hand side), stating that the operand *"must be of type 'any', 'number', 'bigint' or an enum type."* Variables explicitly typed as `any` will bypass this check and will not throw an error.
* **Type Homogeneity:** TypeScript requires both operands to be of the exact same type. You cannot mix `number` and `bigint` without explicit casting. Mixing incompatible but otherwise valid numeric types triggers `TS2365`.

```typescript theme={"dark"}
let num: number = 10;
num |= 2; // Valid

let big: bigint = 10n;
big |= 2n; // Valid

// Mixing types:
// big |= 2; 
// Error TS2365: Operator '|=' cannot be applied to types 'bigint' and 'number'.

// Invalid types:
let str: string = "2";
// num |= str; 
// Error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
```

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