setBigUint64() writes an unsigned 64-bit whole number, given as a BigInt, into eight bytes of a DataView. Use it for values that are never negative and may be far above 4294967295: byte counters, file sizes, 64-bit IDs. Pass the byte offset, the BigInt and optionally true for little-endian order. Values outside 0n to 18446744073709551615n wrap around.
Converts value to a unsigned 64-bit integer (0n to 18446744073709551615n) and writes it into the 8 bytes starting at byteOffset, big-endian. Returns undefined.
view.setBigUint64(byteOffset, value, true)
Writes the same 8 bytes in little-endian order, so the least significant byte lands at byteOffset.
Added in ES2020 together with BigInt. Every current browser and runtime has it. Unlike a BigUint64Array, a DataView has no alignment rule: setBigUint64() works at any byte position, even one that is not a multiple of 8.
Library declarations
JavaScript
DataView.prototype.setBigUint64(byteOffset, value)
DataView.prototype.setBigUint64(byteOffset, value, littleEndian)
// returns undefined; writes 8 bytes starting at byteOffset
// value is converted to a unsigned 64-bit integer (BigInt required)
// needs byteOffset + 8 <= view.byteLength, else RangeError
// littleEndian: false or left out = big-endian
Parameters
Parameter
Description
byteOffset
Where to start writing, 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.
value
The BigInt to store, such as 42n. A plain Number like 42 throws a TypeError (strings such as "42" and booleans are converted). Values outside 0n to 18446744073709551615n wrap around modulo 264.
littleEndian
Optional. 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 Value
Description
undefined
setBigUint64() gives nothing back. Its result is the 8 bytes it changed inside the buffer; read them back with getBigUint64().
JavaScript Examples
Example 1 — Save a Network Byte Counter
A download counter has passed 4 GiB, too much for 32 bits. Save it as an unsigned 64-bit little-endian value.
JavaScript
const stats = new DataView(new ArrayBuffer(8));
let sent = 4294967296n; // already 4 GiB sent
sent += 10n; // ten more bytes
stats.setBigUint64(0, sent, true);
const hex = Array.from(new Uint8Array(stats.buffer), function (b) {
return b.toString(16).padStart(2, "0");
}).join(" ");
console.log(hex); // 0a 00 00 00 01 00 00 00
console.log(String(stats.getBigUint64(0, true))); // 4294967306
A 64-bit ID in hex. BigInt literals can be written in hex too: 0x0123456789abcdefn.
Big-endian splits cleanly. Without true the most significant half goes first, so getUint32(0) is 0x01234567 (printed without the leading zero) and getUint32(4) is 0x89abcdef.
The very first byte. getUint8(0) is 1, the top byte of the ID, because big-endian writes from the most significant end.
Compatibility
Browser & Runtime Support
setBigUint64() arrived in ES2020, together with BigInt and BigUint64Array.
✓ ES2020 · Widely available
DataView.prototype.setBigUint64()
Every current browser and runtime supports it. Only very old engines without BigInt lack it.
97%Current browser support
Google ChromeModern versions · Desktop & Mobile
Full support
Mozilla FirefoxModern versions · Desktop & Mobile
Full support
Apple SafariModern versions · macOS & iOS
Full support
Microsoft EdgeModern versions · Chromium
Full support
OperaModern versions
Full support
Samsung InternetModern versions · Android
Full support
Internet ExplorerNo BigInt support
Not supported
Node.jsCurrent releases · checked on Node 24
Supported
DenoCurrent releases
Supported
BunCurrent releases
Supported
setBigUint64()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
It writes a BigInt into eight bytes as an unsigned 64-bit integer, from 0n up to 18446744073709551615n.
It accepts negative BigInts but wraps them: -1n is stored as 18446744073709551615n. It does not throw.
1 is a Number, and the 64-bit setters only take BigInt values, so it throws a TypeError. Use 1n.
Pass true as the third argument: view.setBigUint64(0, value, true).
Only the lowest 64 bits are kept. For example 2n ** 64n + 3n is stored as 3n.