BigInt( number )
Appending n to end of an integer literal
Parameters: It accepts a single integer literal as string that needs to represent as BigInt.
Return Type: This method returns the given value as BigInt data type.
Example: This example creating a BigInt using the BigInt() function.
let bigNum = BigInt(
let bigHex = BigInt(
let bigBin = BigInt(
Example: This example creating a BigInt by appending n at the end of the number.
let bigNum = 123422222222222222222222222222222222222n
let bigHex = 0x1ffffffeeeeeeeeefn
let bigBin = 0b1010101001010101001111111111111111n
Comparing BigInt other types: A BigInt is similar to a Number in some ways, however, it cannot be used with methods of the builtin Math object and cannot be mixed with instances of Number in operations.
Example: Comparing BigInt with a Number.
typeof 100n === 100 // Returns false
typeof 100n == 100 // Returns true due to coercion
typeof 100n === 'bigint' // Returns true
100n < 101 // Returns true due to coercion
Sorting: An array can hold both primitive data types and BigInts. This allows the sort() method to work when both normal Number and BigInt values are present in the array.
let arr = [4, 2, 5n, 2n]
[2, 2n, 4, 5n]
Usage Recommendation: The following applications are not recommended to be used with BigInt due to its implementation:
- Coercion: Coercing between Number and BigInt can lead to loss of precision, it is recommended to only use BigInt when values greater than 253 are reasonably expected and not to coerce between the two types.
- Cryptography: The operations supported on BigInt are not constant time. BigInt is therefore unsuitable for use in cryptography.
Supported Browsers: The browsers supporting BigInt method are listed below:
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!