Course contentsShow
← JavaScript
Lesson 131 of 2,7234. Working with NumbersFree lesson

Comparison and Equality with BigInt

Learn how BigInt works with <, >, ==, and === when compared to other BigInt or Number values.

Comparison and Equality with BigInt

You'll learn how to compare BigInt values with other BigInts and Numbers using JavaScript's comparison and equality operators.

Core Concept

BigInt values can be compared using the familiar <, >, <=, and >= operators with both other BigInts and regular Numbers. JavaScript handles these comparisons smoothly, converting types as needed for relational checks.

For equality, however, the rules differ:

  • Loose equality (==) allows comparison between BigInt and Number by converting values
  • Strict equality (===) requires both type and value to match, so a BigInt will never strictly equal a Number, even if they represent the same mathematical value

Examples

const big = 100n;
const num = 100;

// Relational comparisons work across types
console.log(big > 50);      // true
console.log(big < num);     // false
console.log(big >= 100);    // true

// Loose equality converts types
console.log(big == num);    // true (100n equals 100)
console.log(10n == 10);     // true

// Strict equality checks type AND value
console.log(big === num);   // false (different types)
console.log(10n === 10);    // false
console.log(10n === 10n);   // true (same type and value)

// Comparing BigInts to each other
console.log(50n < 100n);    // true
console.log(50n === 50n);   // true

Think of it this way: Relational operators (<, >) care about numeric value, so they're flexible. Strict equality (===) cares about identity, including type, so it's stricter.

Key Takeaway: Use <, >, <=, >= freely between BigInt and Number; they compare by numeric value. Use == for loose equality across types, but remember === will always be false when comparing BigInt to Number because they're different types.