Categories
JavaScript Answers

How to convert strings to bigInt in JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *