JavaScript DataView setBigUint64() Method



The JavaScript DataView setBigUint64() method accepts a big integer and stores it as a 64-bit unsigned integer in the 8-byte segment starting from a specified byte offset within this DataView.

There are no strict alignment requirements; you can store multiple bytes at any offset within the bounds of the DataView.

This method throws a 'RangeError' exception if the value of the byteOffset parameter falls outside this bound, and if the given value does not fit for the bigInt unsigned integer, it will throw a 'TypeError' exception.

Syntax

Following is the syntax of the JavaScript DataView setBigUint64() method −

setBigUint64(byteOffset, value, littleEndian)

Parameters

This method accepts three parameters named 'byteOffset', 'value', and 'littleEndian', which are described below −

  • byteOffset − The position in the DataView where the byte will be stored.
  • value − An unsigned 64-bit big integer that needs to be stored.
  • littleEndian − It indicates whether the data is stored in little-endian or big-endian format.

Return value

This method returns 'undefined', as it only stores the byte value.

Example 1

The following is the basic example of the JavaScript DataView setBigUint64() method.






Output

The above program stores the specified bigInt unsigned value within the current DataView and displays it as −

The byte offset: 0
Value: 18446744073709551615
The stored value: 18446744073709551615

Example 2

If you try to print the result of this method, it will return an 'undefined' as the output.






Output

After executing the above program, it will return an 'undefined' result.

The byte offset: 1
Value: 18446744073709551615
The data_view.setBigUnit64() method returns: undefined

Example 3

If the value of the byteOffset parameter falls outside the bounds of this data view, it will throw a 'RangeError' exception.






Output

Once the above program is executed, it will throw a 'RangeError' exception.

The byte offset: 0
Value: 23456543212
TypeError: Cannot convert 23456543212 to a BigInt

Example 4

If the given value does not fit for the bigInt unsigned integer, this method will throw a 'TypeError' exception.



JavaScript DataView setBigUint64() Method





Output

The above program throws a 'TypeError' exception as −

The byte offset: 0
Value: 23456543212
TypeError: Cannot convert 23456543212 to a BigInt
Advertisements