How to Convert a String to BigInt in JavaScript?

You can convert a JavaScript string to a bigint value by using the BigInt() wrapper object, for example, like so:

// ES10+
const numericStr = '9007199254740991123456789';
const bigIntVal = BigInt(numericStr);

console.log(bigIntVal); // 9007199254740991123456789n

The "n" at the end of a number merely suggests that the number is a bigint primitive.

Hope you found this post useful. It was published . Please show your love and support by sharing this post.