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

`bigint` is a primitive data type in TypeScript used to represent arbitrarily large integers beyond the safe integer limit of the standard `number` type (`Number.MAX_SAFE_INTEGER`, or $2^{53} - 1$).

You can initialize a `bigint` by appending an `n` suffix to an integer literal or by calling the global `BigInt()` function.

```typescript theme={"dark"}
const literalBigInt: bigint = 9007199254740992n;
const constructedBigInt: bigint = BigInt("9007199254740992");
const hexBigInt: bigint = 0x1fffffffffffffn;
```

## Type Interoperability and Strictness

TypeScript enforces strict separation between `bigint` and `number`. There is no implicit type coercion between the two primitives. Attempting to mix them in arithmetic operations will result in a compile-time type error, requiring explicit casting to perform operations across the two types.

While `bigint` and `number` can be safely mixed in relational comparisons (`<`, `>`, `<=`, `>=`) and loose equality comparisons (`==`, `!=`), strict equality comparisons (`===`, `!==`) are forbidden. Because `bigint` and `number` are disjoint types with no overlap, TypeScript explicitly rejects strict equality checks between them and will throw a compile-time error (TS2367).

```typescript theme={"dark"}
const bigVal: bigint = 100n;
const numVal: number = 50;

// TS2365: Operator '+' cannot be applied to types 'bigint' and 'number'.
// const invalidSum = bigVal + numVal; 

const validBigIntSum: bigint = bigVal + BigInt(numVal);
const validNumberSum: number = Number(bigVal) + numVal;

// Relational and loose equality comparisons are valid
const isGreater: boolean = bigVal > numVal; // true
const isLooselyEqual: boolean = bigVal == 100; // true

// TS2367: This condition will always return 'false' since the types 'bigint' and 'number' have no overlap.
// const isStrictlyEqual: boolean = bigVal === 100;
```

## Mathematical and Bitwise Operations

`bigint` supports standard arithmetic operators (`+`, `-`, `*`, `/`, `%`, `**`) and bitwise operators (`&`, `|`, `^`, `~`, `<<`, `>>`). Notably, the unsigned right shift operator (`>>>`) is explicitly unsupported for `bigint` types, as `bigint` does not have a fixed bit-width to shift into.

Because `bigint` strictly represents whole numbers, division operations inherently truncate fractional components towards zero. Furthermore, `bigint` primitives are incompatible with the built-in `Math` object methods, which strictly expect `number` arguments.

```typescript theme={"dark"}
// Division truncates towards zero
const division: bigint = 5n / 2n; // Evaluates to 2n

// Bitwise operations are supported, except >>>
const bitwiseAnd: bigint = 0b101n & 0b011n; // Evaluates to 1n

// TS2736: Operator '>>>' cannot be applied to type 'bigint'.
// const invalidShift = 10n >>> 1n; 

// TS2345: Argument of type 'bigint' is not assignable to parameter of type 'number'.
// const absolute = Math.abs(-10n); 
```

## Compiler Configuration

Because `bigint` is a relatively recent ECMAScript feature, the TypeScript compiler requires a specific target to emit valid code. Your `tsconfig.json` must have the `target` set to `ES2020` or later. If targeting an older ECMAScript version, TypeScript will throw a compilation error, as `bigint` cannot be polyfilled or down-compiled to standard JavaScript numbers without losing precision.

```json theme={"dark"}
{
  "compilerOptions": {
    "target": "ES2020",
    "lib": ["ES2020"]
  }
}
```

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