Javascript BigInt Comparisons

Introduction

A BigInt is not strictly equal to a Number using ===.

== returns true

console.log(0n === 0);
console.log(0n == 0);

A Number and a BigInt can be compared:

console.log(1n < 2);//from w  w w .  j  av a  2  s. c  o  m
console.log(2n > 1);
console.log(2 > 2n);
console.log(2n > 2);
console.log(2n >= 2);

Number and BigInt can be mixed in arrays and sorted:

const a = [4n, 16, -12n, 10, 14, 10, 10n] ;
a.sort();// w  w  w  .  ja v  a  2  s  . c om
console.log(a);



PreviousNext

Related