Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

BigInt64Array: signed 64-bit integers

BigInt64Array stores BigInt values as signed 64-bit integers and wraps them modulo 2^64.

Version: ECMAScript 2020 onward; example target: Node.js 24.22.2

Syntax

new BigInt64Array(); new BigInt64Array(length); new BigInt64Array(source); new BigInt64Array(buffer[, byteOffset[, length]])

new BigInt64Array(source?, byteOffset?, length?) creates a signed BigInt typed array with 8 bytes per element. The source can be an element count, an iterable or array-like value, another typed array with BigInt content type (BigInt64Array or BigUint64Array); a numeric typed array has an incompatible content type and throws TypeError, or an ArrayBuffer/SharedArrayBuffer. The buffer form creates a view without copying, and byteOffset must be a multiple of 8. New elements are zero-filled.

On assignment, a value is converted to BigInt, reduced modulo 2^64, and interpreted in two’s-complement range -2^63 through 2^63-1. Thus 2n ** 63n becomes -2n ** 63n. An ordinary Number is not accepted and throws TypeError; use BigInt(number) for an intentional conversion, but only when number is integral; a fractional Number throws RangeError. Typed arrays use platform-native byte order, so use DataView for a fixed binary format.

The constructor requires new. Length goes through ToIndex: fractions are truncated toward zero, NaN and undefined become 0, and -0.5 becomes -0 and therefore 0. A negative result after ToIntegerOrInfinity, infinity, exceeding the range, a misaligned offset, or a range outside the buffer throws RangeError; a detached buffer or an unconvertible value throws TypeError. The API was standardized in ECMAScript 2020, and BigInt64Array.BYTES_PER_ELEMENT is 8.

Examples

const signed = new BigInt64Array([1n, -2n, 2n ** 63n]);
console.log(Array.from(signed, String).join(","));

const wrapped = new BigInt64Array([2n ** 64n + 5n, -(2n ** 64n) - 1n]);
console.log(Array.from(wrapped, String).join(","));

const buffer = new ArrayBuffer(16);
const view = new BigInt64Array(buffer, 8, 1);
view[0] = 42n;
console.log(view.byteOffset, view.byteLength, view[0], BigInt64Array.BYTES_PER_ELEMENT);

try { signed[0] = 1; } catch (error) { console.log(error instanceof TypeError); }

Result

1,-2,-9223372036854775808
5,-1
8 8 42n 8
true

Sources