JavaScript DataView getBigInt64() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
Instance method

Definition

getBigInt64() reads eight bytes from a DataView and returns a signed 64-bit whole number as a BigInt, from -9223372036854775808n to 9223372036854775807n. A normal Number cannot hold every whole number that large exactly, which is why this method returns a BigInt (a whole number written with a trailing n). Like the other multi-byte methods, it reads big-endian unless you pass true.

Remember
const view = new DataView(new ArrayBuffer(8));
view.setBigInt64(0, -5n);
view.getBigInt64(0);           // -5n
view.getBigUint64(0);          // 18446744073709551611n
typeof view.getBigInt64(0);    // "bigint"
view.getBigInt64(1);           // RangeError

Syntax

Call getBigInt64() on a DataView object with a byte position and, if the data is little-endian, true.

JavaScript
dataview.getBigInt64(byteOffset)
dataview.getBigInt64(byteOffset, littleEndian)
CallWhat it does
view.getBigInt64(byteOffset)Reads the 8 bytes starting at byteOffset in big-endian order (most significant byte first) and returns a signed whole number from -9223372036854775808n to 9223372036854775807n.
view.getBigInt64(byteOffset, true)Reads the same 8 bytes in little-endian order (least significant byte first), the order used by most file formats from PCs, such as WAV and BMP.

Added in ES2020 together with BigInt. Every current browser and runtime has it. Unlike a BigInt64Array, a DataView has no alignment rule: getBigInt64() works at any byte position, even one that is not a multiple of 8.

Library declarations
JavaScript
DataView.prototype.getBigInt64(byteOffset)
DataView.prototype.getBigInt64(byteOffset, littleEndian)

// returns a BigInt: -9223372036854775808n to 9223372036854775807n
// reads 8 bytes starting at byteOffset (counted from the start of the view)
// needs byteOffset + 8 <= view.byteLength, else RangeError
// littleEndian: false or left out = big-endian

Parameters

ParameterDescription
byteOffsetWhere to start reading, counted in bytes from the start of the view (not of the underlying buffer). It is converted to a whole number, so 1.9 means 1 and "2" means 2. All 8 bytes must fit: byteOffset + 8 may not be larger than view.byteLength. A negative or too-large offset throws a RangeError.
littleEndianOptional. Leave it out (or pass false) for big-endian: the most significant of the 8 bytes comes first. Pass true for little-endian: the least significant byte comes first. Any truthy value, such as 1, also means little-endian.

Return Value

Return ValueDescription
BigIntA BigInt from -9223372036854775808n to 9223372036854775807n, built from the 8 bytes at byteOffset. Print it with String(), and use Number() only when it is small enough.

JavaScript Examples

Example 1 — Read a Time Stored in Milliseconds

A timestamp in milliseconds is too big for 32 bits, so binary formats store it in 8 bytes. Read it and turn it into a date.

JavaScript
const view = new DataView(new ArrayBuffer(8));
view.setBigInt64(0, 1735689600000n);   // milliseconds since 1970

const ms = view.getBigInt64(0);
console.log(String(ms));                           // 1735689600000
console.log(new Date(Number(ms)).toISOString());   // 2025-01-01T00:00:00.000Z
Try It Yourself

How It Works

  1. Milliseconds need more than 32 bits. A time in milliseconds, such as 1735689600000, is far above 4294967295, so it is stored in 8 bytes.
  2. Read it as a BigInt. getBigInt64(0) returns 1735689600000n; String() prints it without the n.
  3. Convert for Date. The value is well below Number.MAX_SAFE_INTEGER, so Number(ms) is exact and new Date() shows 1 January 2025.

Example 2 — Eight Bytes of 0xff, Read Two Ways

Fill 8 bytes with 0xff, read them as signed and unsigned, then clear the sign bit.

JavaScript
const view = new DataView(new Uint8Array(8).fill(0xff).buffer);

console.log(String(view.getBigInt64(0)));    // -1
console.log(String(view.getBigUint64(0)));   // 18446744073709551615

view.setUint8(0, 0x7f);
console.log(String(view.getBigInt64(0)));    // 9223372036854775807
Try It Yourself

How It Works

  1. Eight bytes of ff. new Uint8Array(8).fill(0xff) sets all 64 bits to 1.
  2. Signed sees -1. In two’s complement all bits on means -1, so getBigInt64() returns -1n while getBigUint64() returns the maximum unsigned value.
  3. Clear the sign bit. Changing the first byte to 7f turns the top bit off, and the same 8 bytes now read as the largest positive value, 9223372036854775807n.

Example 3 — Keep a Huge Database ID Exact

Some databases hand out 64-bit IDs larger than JavaScript Numbers can hold exactly. Read one with getBigInt64() and see what Number() would do.

JavaScript
const view = new DataView(new ArrayBuffer(8));
view.setBigInt64(0, 9007199254740993n, true);   // a database row id

const id = view.getBigInt64(0, true);
console.log(String(id));            // 9007199254740993
console.log(String(Number(id)));    // 9007199254740992
console.log(id > BigInt(Number.MAX_SAFE_INTEGER));   // true
Try It Yourself

How It Works

  1. An ID above the safe limit. 9007199254740993 is larger than Number.MAX_SAFE_INTEGER (9007199254740991).
  2. BigInt keeps every digit. getBigInt64(0, true) reads the little-endian bytes back as exactly 9007199254740993n.
  3. Number() would lose it. Converting to a Number rounds the ID to 9007199254740992, a different row. Keep such IDs as BigInt or as strings.

Browser & Runtime Support

getBigInt64() arrived in ES2020, together with BigInt and BigInt64Array.

✓ ES2020 · Widely available

DataView.prototype.getBigInt64()

Every current browser and runtime supports it. Only very old engines without BigInt lack it.

97% Current browser support
Google Chrome Modern versions · Desktop & Mobile
Full support
Mozilla Firefox Modern versions · Desktop & Mobile
Full support
Apple Safari Modern versions · macOS & iOS
Full support
Microsoft Edge Modern versions · Chromium
Full support
Opera Modern versions
Full support
Samsung Internet Modern versions · Android
Full support
Internet Explorer No BigInt support
Not supported
Node.js Current releases · checked on Node 24
Supported
Deno Current releases
Supported
Bun Current releases
Supported
getBigInt64() All current engines

Bottom line: Safe in today’s browsers. If you must support an engine without BigInt, check typeof BigInt === "function" first.

Frequently Asked Questions

A BigInt, such as -5n. typeof view.getBigInt64(0) is "bigint", not "number".
A Number can only hold whole numbers exactly up to 9007199254740991. A 64-bit integer goes much higher, so a BigInt is needed to keep every digit.
Use String(value) or value.toString(). Both give the digits without the trailing n.
getBigInt64() treats the top bit as a sign and returns -2 to the power 63 up to 2 to the power 63 minus 1. getBigUint64() returns 0 up to 2 to the power 64 minus 1.
No, mixing BigInt and Number throws a TypeError. Use a BigInt literal such as 1n, or convert one side first.

Next: getBigUint64()

Read 8 bytes as an unsigned BigInt: file sizes, hashes and 64-bit IDs.

getBigUint64() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful