JavaScript DataView setBigUint64() Method

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

Definition

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.

Remember
const view = new DataView(new ArrayBuffer(8));
view.setBigUint64(0, 255n);     // undefined
view.getUint8(7);               // 255
view.setBigUint64(0, -1n);
view.getBigUint64(0);           // 18446744073709551615n
view.setBigUint64(0, 1);        // TypeError

Syntax

Call setBigUint64() on a DataView object with a byte position and the value to write, plus true if you need little-endian order.

JavaScript
dataview.setBigUint64(byteOffset, value)
dataview.setBigUint64(byteOffset, value, littleEndian)
CallWhat it does
view.setBigUint64(byteOffset, value)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

ParameterDescription
byteOffsetWhere 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.
valueThe 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.
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
undefinedsetBigUint64() 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
Try It Yourself

How It Works

  1. A counter past 32 bits. After 4 GiB the count is 4294967296n, one more than a 32-bit number can hold, and 10n more bytes are added.
  2. Saved in 8 little-endian bytes. The low byte, 0a (10), comes first, and the 1 that stands for 4 GiB appears in byte 4.
  3. Nothing was lost. Reading with getBigUint64(0, true) returns the full 4294967306n.

Example 2 — What Happens Past the Largest Value

Write the largest unsigned 64-bit value, then go past it, then write a negative BigInt.

JavaScript
const view = new DataView(new ArrayBuffer(8));
const max = 2n ** 64n - 1n;

view.setBigUint64(0, max);
console.log(String(view.getBigUint64(0)));   // 18446744073709551615

view.setBigUint64(0, max + 4n);
console.log(String(view.getBigUint64(0)));   // 3

view.setBigUint64(0, -2n);
console.log(String(view.getBigUint64(0)));   // 18446744073709551614
Try It Yourself

How It Works

  1. Fill every bit. 2n ** 64n - 1n is the largest unsigned 64-bit value and is stored unchanged.
  2. Going past the end restarts at zero. max + 4n is 3 more than 2 to the power 64, so only 3n is kept, like an odometer that rolls over.
  3. Negatives wrap to the top. -2n is stored as 18446744073709551614n instead of causing an error.

Example 3 — Write a 64-bit ID and Read Its 32-bit Halves

Write a hex ID with setBigUint64() and read it back as two 32-bit numbers and its first byte.

JavaScript
const view = new DataView(new ArrayBuffer(8));
view.setBigUint64(0, 0x0123456789abcdefn);

console.log(view.getUint32(0).toString(16));   // 1234567
console.log(view.getUint32(4).toString(16));   // 89abcdef
console.log(view.getUint8(0));                 // 1
Try It Yourself

How It Works

  1. A 64-bit ID in hex. BigInt literals can be written in hex too: 0x0123456789abcdefn.
  2. 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.
  3. The very first byte. getUint8(0) is 1, the top byte of the ID, because big-endian writes from the most significant end.

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 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
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.

Next: setFloat16()

Write decimals in only 2 bytes with the newest DataView setter.

setFloat16() 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