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

The sign-propagating right shift operator (`>>`) shifts the binary representation of the first operand to the right by the number of bits specified by the second operand. It discards bits shifted off to the right and preserves the original number's sign by copying the leftmost bit (the sign bit) into the newly vacated bit positions on the left. The operator supports both `Number` and `BigInt` types.

```javascript theme={"dark"}
a >> b
```

## Technical Mechanics: `Number` Operands

When both operands are standard JavaScript `Number` values, the operator applies 32-bit integer semantics:

1. **Type Coercion:** The left operand (`a`) is converted to a 32-bit signed integer using the ECMAScript `ToInt32` abstract operation. The right operand (`b`) is converted to a 32-bit unsigned integer using the `ToUint32` abstract operation. Fractional parts are truncated. Non-numeric values (like `NaN`, `null`, or `undefined`) are coerced to `0`.
2. **Modulo Shift Amount:** The evaluated right operand is masked to 5 bits (`b & 0x1F`). The effective shift amount is always `b % 32`. Shifting by 32, 64, or 96 bits is functionally identical to shifting by 0 bits.
3. **Sign Extension:** JavaScript uses the 32nd bit of the `ToInt32` representation as the sign indicator (`0` for positive, `1` for negative). If the original number is positive, `0`s are shifted in from the left. If negative, `1`s are shifted in from the left, maintaining the two's complement structure.

## Technical Mechanics: `BigInt` Operands

When both operands are `BigInt` values, the operator applies arbitrary-precision semantics:

1. **Arbitrary Precision:** `BigInt` values are not truncated to 32 bits. They conceptually operate on an infinite-length two's complement binary representation.
2. **Unmasked Shift Amount:** The right operand is **not** masked. A `BigInt` can be shifted by more than 32 bits, and the operation mathematically evaluates to `a / (2n ** b)` (rounded towards negative infinity).
3. **Sign Extension:** The sign is preserved mathematically without relying on a fixed 32nd bit.

## Syntax Visualization

**Number: Positive Integer Shift**
When shifting a positive integer, the sign bit is `0`, so `0`s are populated from the left.

```javascript theme={"dark"}
9 >> 2; // Evaluates to 2

// 32-bit binary representation of 9:
// 00000000000000000000000000001001

// Shifted right by 2 positions (vacated bits filled with 0):
// 00000000000000000000000000000010 // Evaluates to 2
```

**Number: Negative Integer Shift**
When shifting a negative integer, the sign bit is `1`, so `1`s are populated from the left.

```javascript theme={"dark"}
-9 >> 2; // Evaluates to -3

// 32-bit two's complement representation of -9:
// 11111111111111111111111111110111

// Shifted right by 2 positions (vacated bits filled with 1):
// 11111111111111111111111111111101 // Evaluates to -3
```

**BigInt: Arbitrary Precision Shift**
`BigInt` shifts process the full magnitude without 32-bit truncation or modulo masking.

```javascript theme={"dark"}
10000000000000n >> 33n; // Evaluates to 1164n

// Mathematically equivalent to:
// Math.floor(10000000000000 / (2 ** 33))
```

## Edge Cases and Coercion Behavior

**Type Mixing (`TypeError`)**
Mixing `Number` and `BigInt` operands is strictly prohibited and throws a `TypeError`.

```javascript theme={"dark"}
10n >> 2; // TypeError: Cannot mix BigInt and other types
10 >> 2n; // TypeError: Cannot mix BigInt and other types
```

**Floating-Point Truncation**
Because of the mandatory `ToInt32` conversion for standard numbers, the `>>` operator strips floating-point decimals before shifting:

```javascript theme={"dark"}
10.99 >> 1;   // Evaluates to 5 (10.99 is truncated to 10)
-10.99 >> 1;  // Evaluates to -5 (-10.99 is truncated to -10)
```

**Modulo 32 Behavior (Numbers Only)**
For standard numbers, shift amounts exceeding 31 are wrapped via the 5-bit mask:

```javascript theme={"dark"}
5 >> 32;      // Evaluates to 5 (32 % 32 = 0, so 5 >> 0)
5 >> 33;      // Evaluates to 2 (33 % 32 = 1, so 5 >> 1)
```

**Non-Numeric Coercion**
Standard type coercion applies to non-numeric `Number` operands:

```javascript theme={"dark"}
NaN >> 1;     // Evaluates to 0 (NaN coerces to 0)
"12" >> 1;    // Evaluates to 6 (String "12" coerces to integer 12)
```

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