How to convert strings to bigInt in JavaScript?

Sometimes, we want to convert strings to bigInt in JavaScript.

In this article, we’ll look at how to convert strings to bigInt in JavaScript.

How to convert strings to bigInt in JavaScript?

To convert strings to bigInt in JavaScript, we can use the BigInt function.

For instance, we write:

const string = '8795485488564835575723945398498489398434434';
const bigInt = BigInt(string);
console.log(bigInt)

to call BigInt with string to convert string to a bigint.

Therefore, bigInt is 8795485488564835575723945398498489398434434n .

Conclusion

To convert strings to bigInt in JavaScript, we can use the BigInt function.