Function createBigInt

  • Create a bigint from a number-like value.

    • If the value is a number, it is converted to a bigint.
    • If the value is a bigint, it is returned as-is.
    • If the value is a string, it is interpreted as a decimal number and converted to a bigint.
    • If the value is a hex string (i.e., it starts with "0x"), it is interpreted as a hexadecimal number and converted to a bigint.

    Example

    const value = createBigInt('0x010203');
    console.log(value); // 16909060n

    const otherValue = createBigInt(123);
    console.log(otherValue); // 123n

    Returns

    The created bigint.

    Throws

    If the value is not a number-like value.

    Parameters

    • value: string | number | bigint

      The value to create the bigint from.

    Returns bigint