setBigInt64() writes a signed 64-bit whole number into eight bytes of a DataView. The value must be a BigInt (such as 42n), because 64-bit integers can be larger than a Number can hold exactly. Pass the byte offset, the BigInt and optionally true for little-endian order. Values outside -9223372036854775808n to 9223372036854775807n wrap around.
Converts value to a signed 64-bit integer (-9223372036854775808n to 9223372036854775807n) and writes it into the 8 bytes starting at byteOffset, big-endian. Returns undefined.
view.setBigInt64(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 BigInt64Array, a DataView has no alignment rule: setBigInt64() works at any byte position, even one that is not a multiple of 8.
Library declarations
JavaScript
DataView.prototype.setBigInt64(byteOffset, value)
DataView.prototype.setBigInt64(byteOffset, value, littleEndian)
// returns undefined; writes 8 bytes starting at byteOffset
// value is converted to a signed 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 -9223372036854775808n to 9223372036854775807n 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
setBigInt64() gives nothing back. Its result is the 8 bytes it changed inside the buffer; read them back with getBigInt64().
JavaScript Examples
Example 1 — Write a Millisecond Timestamp and Inspect It
Write a time in milliseconds with setBigInt64() and look at the 8 bytes it produced.
The largest signed value. 9223372036854775807n (2 to the power 63, minus 1) still fits and comes back unchanged.
One more wraps to the minimum. 9223372036854775808n does not fit, so it wraps around by 2 to the power 64 and reads back as -9223372036854775808n.
Minus one fills every byte.setBigInt64(0, -1n, true) stores 64 one-bits, so the first and last bytes are both 255.
Compatibility
Browser & Runtime Support
setBigInt64() arrived in ES2020, together with BigInt and BigInt64Array.
✓ ES2020 · Widely available
DataView.prototype.setBigInt64()
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
setBigInt64()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
The 64-bit setters only accept BigInt values. Write 5n or BigInt(5) instead of 5.
undefined. The eight bytes it wrote are the result; read them with getBigInt64().
It wraps around modulo 2 to the power 64. For example 2n ** 63n reads back as -9223372036854775808n.
Convert the millisecond number to a BigInt first: view.setBigInt64(0, BigInt(Date.now())).
They write the same 64 bits. setBigInt64() thinks of the range -2 to the power 63 up to 2 to the power 63 minus 1; setBigUint64() thinks of 0 up to 2 to the power 64 minus 1.