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

The `>>=` (sign-propagating right shift assignment) operator shifts the binary representation of the left operand to the right by the number of bits specified by the right operand, preserves the sign bit, and assigns the evaluated result back to the left operand.

## Syntax

```javascript theme={"dark"}
x >>= y
```

This is syntactically equivalent to `x = x >> y`, except that the reference to `x` is evaluated only once.

## Technical Mechanics

When the JavaScript engine evaluates `x >>= y`, it performs the following sequence of operations:

1. **Numeric Coercion (`ToNumeric`)**: Both operands are evaluated and coerced to numeric values.
   * If either operand is a `Symbol`, a `TypeError` is thrown.
   * If the resulting coerced types differ (e.g., one evaluates to a `Number` and the other to a `BigInt`), a `TypeError` is thrown.
2. **Type-Specific Shift Execution**:
   * **For `Number` Operands**:
     * **32-bit Conversion**: The left operand undergoes `ToInt32` (converted to a 32-bit signed integer using Two's complement). The right operand undergoes `ToUint32` (converted to a 32-bit unsigned integer). Fractional parts are truncated.
     * **Right Operand Masking**: The right operand is masked to its lowest 5 bits using a bitwise AND operation (`y & 0x1F`). This restricts the shift count to a value between `0` and `31`. Note that this is a strict bitwise mask, which differs from the remainder operator (`%`) for negative numbers (e.g., `-1 & 0x1F` evaluates to `31`, whereas `-1 % 32` evaluates to `-1`).
     * **Bitwise Shift**: The bits of `x` are shifted right by the masked `y` value. Bits shifted past the 0th position (Least Significant Bit) are discarded.
     * **Sign Propagation**: The Most Significant Bit (MSB) of the original 32-bit integer `x` dictates the bits shifted in from the left. If `x` is positive (MSB is `0`), `0`s are shifted in. If `x` is negative (MSB is `1`), `1`s are shifted in.
   * **For `BigInt` Operands**:
     * **Arbitrary Precision**: BigInts do not undergo 32-bit truncation, and the right operand is not subjected to 5-bit masking.
     * **Negative Shift Validation**: If the right operand is negative, a `RangeError` is thrown. This is a strict departure from `Number` operands, which safely wrap negative shift counts via bitwise masking.
     * **Mathematical Shift**: The left operand is shifted right by the exact value of the right operand. Mathematically, this evaluates to the floor of the left operand divided by 2 to the power of the right operand: ⌊x / 2<sup>y</sup>⌋. This operation rounds towards negative infinity, which is a critical distinction from JavaScript's BigInt division operator (`/`) that truncates towards zero.
3. **Assignment**: The resulting value is assigned back to the variable `x`.

## Evaluation Examples

### Positive Integer Shift (`Number`)

```javascript theme={"dark"}
let a = 10; 
// 32-bit binary: 00000000000000000000000000001010

a >>= 2;    
// Shifts right by 2. MSB is 0, so 0s are pushed from the left.
// Result binary: 00000000000000000000000000000010
// a is now 2
```

### Negative Integer Shift (`Number`)

```javascript theme={"dark"}
let b = -10; 
// 32-bit binary: 11111111111111111111111111110110 (Two's complement)

b >>= 2;     
// Shifts right by 2. MSB is 1, so 1s are pushed from the left.
// Result binary: 11111111111111111111111111111101
// b is now -3
```

### Bitwise Masking Behavior (`Number`)

```javascript theme={"dark"}
let c = 100;
c >>= 33; 
// 33 & 0x1F evaluates to 1. 
// The operation executed is effectively c >>= 1.
// c is now 50

let d = 100;
d >>= -1;
// -1 & 0x1F evaluates to 31.
// The operation executed is effectively d >>= 31.
// d is now 0
```

### BigInt Shift and Rounding

```javascript theme={"dark"}
let e = 100n;
e >>= 33n;
// No 5-bit masking occurs. Shifts right by exactly 33 bits.
// e is now 0n

let f = -5n;
f >>= 1n;
// Mathematically: floor(-5 / 2^1) = -3.
// f is now -3n. 
// (Note: -5n / 2n evaluates to -2n, demonstrating the rounding difference).
```

### Type Coercion and Errors

```javascript theme={"dark"}
let g = 15.99;
g >>= "1"; 
// "1" is coerced to Number 1. 15.99 undergoes ToInt32 (becomes 15).
// g is now 7

let h = 10n;
h >>= -1n;
// RangeError: Right-hand side of 'shift right' operator must be non-negative

let i = 10n;
i >>= 2; 
// TypeError: Cannot mix BigInt and other types, use explicit conversions

let j = 5;
j >>= Symbol("shift"); 
// TypeError: Cannot convert a Symbol value to a number
```

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