Advertisement
Advanced JavaScript, ArrayBuffer, TypedArrays & Binary Data

How does BigInt64Array differ from a standard numeric TypedArray?

Short answer

BigInt64Array (and BigUint64Array) store 64-bit integers as BigInt values instead of JS Numbers, avoiding the precision loss that happens with regular Numbers beyond 2^53. Reading an element returns a BigInt, not a Number.

Save JavaScript mock interview
Advertisement
AModel answer
BigInt64Array (and BigUint64Array) store 64-bit integers as BigInt values instead of JS Numbers, avoiding the precision loss that happens with regular Numbers beyond 2^53. Reading an element returns a BigInt, not a Number.
const arr = new BigInt64Array(1);
arr[0] = 9007199254740993n;
console.log(arr[0]); // 9007199254740993n
Real-world example
Storing 64-bit timestamps or IDs precisely when interfacing with binary protocols like protobuf.
Likely follow-ups
  • Can you mix BigInt and Number in arithmetic?
Related topics