Convert a number to a hexadecimal string. This verifies that the number is a non-negative safe integer.
To convert a bigint to a hexadecimal string instead, use bigIntToHex.
bigint
numberToHex(0); // '0x0'numberToHex(1); // '0x1'numberToHex(16); // '0x10'
The hexadecimal string, with the "0x"-prefix.
If the number is not a non-negative safe integer.
The number to convert to a hexadecimal string.
Convert a number to a hexadecimal string. This verifies that the number is a non-negative safe integer.
To convert a
bigint
to a hexadecimal string instead, use bigIntToHex.Example
Returns
The hexadecimal string, with the "0x"-prefix.
Throws
If the number is not a non-negative safe integer.