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.


This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.