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

The `>` (greater than) operator is a relational binary operator that evaluates whether its left operand is strictly greater than its right operand, returning a boolean value (`true` or `false`).

```typescript theme={"dark"}
leftOperand > rightOperand
```

In TypeScript, the `>` operator applies strict compile-time type checking to restrict the unpredictable implicit type coercion (Abstract Relational Comparison) that occurs in standard JavaScript.

## Type Compatibility Rules

TypeScript requires operands to be of compatible, comparable types. The compiler permits the `>` operator for the following types:

1. **Numeric Types (`number`, `bigint`)**: Evaluates the algebraic magnitude. TypeScript explicitly allows cross-type relational comparisons between `number` and `bigint`. Comparisons involving `NaN` always evaluate to `false`.
2. **String Types (`string`)**: Evaluates lexicographically based on the sequence of 16-bit unsigned integer values (UTF-16 code units).
3. **Enums (Numeric and String)**: Numeric enums are compared by their underlying numeric values. String enums are assignable to the `string` type and are compared lexicographically.
4. **Date Objects (`Date`)**: Evaluates based on their underlying numeric time value (milliseconds since the epoch) via the internal `valueOf()` method.

```typescript theme={"dark"}
// Valid syntax and type comparisons
const numCheck: boolean = 10 > 5;           // true
const bigIntCheck: boolean = 10n > 5n;      // true
const mixedNumCheck: boolean = 10 > 5n;     // true (number > bigint is allowed)
const strCheck: boolean = "Z" > "A";        // true

enum StringEnum { A = "A", B = "B" }
const strEnumCheck: boolean = StringEnum.B > StringEnum.A; // true

const dateCheck: boolean = new Date("2024-02-01") > new Date("2024-01-01"); // true
```

## Compiler Errors

If you attempt to use the `>` operator on incompatible types, TypeScript will throw a compile-time error (`TS2365`). While `number` and `bigint` can be mixed, TypeScript intentionally blocks all other cross-type comparisons (e.g., `number > string`). It also strictly blocks comparisons between booleans, arrays, and complex objects (excluding `Date`), unless explicitly bypassed using the `any` type.

```typescript theme={"dark"}
// TS2365: Operator '>' cannot be applied to types 'number' and 'string'.
const invalidMixed = 10 > "5"; 

// TS2365: Operator '>' cannot be applied to types 'boolean' and 'boolean'.
const invalidBool = true > false; 

// TS2365: Operator '>' cannot be applied to types 'number[]' and 'number[]'.
const invalidArray = [1, 2] > [1]; 
```

## Bypassing Type Checks

If operands are typed as `any`, TypeScript defers to the JavaScript runtime behavior. The JavaScript engine will attempt to coerce the operands into primitives (preferring numbers) using the internal `ToPrimitive` and `ToNumeric` abstract operations before performing the comparison.

```typescript theme={"dark"}
const left: any = [2];
const right: any = 1;

// Compiles successfully due to 'any'. 
// At runtime, [2] is coerced to "2", then to 2. 2 > 1 evaluates to true.
const bypassedCheck: boolean = left > right; 
```

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