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

The `>>=` (sign-propagating right shift assignment) operator evaluates the binary representation of its left operand, shifts it to the right by the number of bits specified by the right operand, and assigns the result back to the left operand while preserving the original sign.

**Syntax**

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

This is the compound assignment equivalent of the standard right shift operator:

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

**Underlying Mechanics: `number` Operands**

1. **Operand Conversion:** TypeScript (following ECMAScript specifications) implicitly coerces the left operand to a 32-bit signed integer (`ToInt32`) using two's complement representation. The right operand is coerced to a 32-bit unsigned integer (`ToUint32`). Any fractional components are truncated before the shift occurs.
2. **Shift Masking:** The right operand is masked with `0x1F` (bitwise AND with 31, i.e., `y & 0x1F`). This ensures the shift amount is always strictly between 0 and 31, preventing out-of-bounds shifts. This bitwise mask is distinct from the remainder operator (`%`); for example, a negative shift amount like `-1` correctly masks to `31` (`-1 & 0x1F`), whereas `-1 % 32` would evaluate to `-1`.
3. **Sign Propagation:** As bits are shifted to the right, the vacated most significant bits (MSB) on the left are filled with a copy of the original sign bit. If the original number was positive, the new bits are `0`. If the original number was negative, the new bits are `1`.
4. **Bit Discard:** Bits shifted past the least significant bit (LSB) on the right are permanently discarded.

**Underlying Mechanics: `bigint` Operands**
When both operands are of type `bigint`, the operator behaves differently:

1. **No 32-bit Truncation:** Operands are not coerced to 32-bit integers. They are treated as having an infinite-length two's complement representation.
2. **No Shift Masking:** The right operand is *not* masked with `0x1F`. The left operand is shifted by the exact magnitude of the right operand.
3. **Errors:** A negative right operand throws a `RangeError`. Mixing `number` and `bigint` operands throws a `TypeError`.

**Behavioral Examples**
*Positive Integer Shift (`number`):*

```typescript theme={"dark"}
let a = 20; // Binary: 00000000000000000000000000010100
a >>= 2;    // Shifts right by 2 bits. Vacated MSBs filled with 0.
// Result: 5   (Binary: 00000000000000000000000000000101)
```

*Negative Integer Shift (`number`):*

```typescript theme={"dark"}
let b = -20; // Binary: 11111111111111111111111111101100 (Two's complement)
b >>= 2;     // Shifts right by 2 bits. Vacated MSBs filled with 1.
// Result: -5  (Binary: 11111111111111111111111111111011)
```

*Shift Masking (`number`):*

```typescript theme={"dark"}
let c = 10;
c >>= 33; // 33 & 0x1F evaluates to 1. Shifts right by 1 bit.
// Result: 5

let d = 10;
d >>= -1; // -1 & 0x1F evaluates to 31. Shifts right by 31 bits.
// Result: 0
```

*BigInt Shift (`bigint`):*

```typescript theme={"dark"}
let e = 10n;
e >>= 33n; // No masking occurs. Shifts right by 33 bits.
// Result: 0n

let f = -20n;
f >>= 2n; // Sign propagation still applies to BigInts.
// Result: -5n
```

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