Categories
JavaScript Answers

How to define a JavaScript long integer?

Spread the love

Sometimes, we want to define a JavaScript long integer.

In this article, we’ll look at how to define a JavaScript long integer.

How to define a JavaScript long integer?

To define a JavaScript long integer, we can define a bigint.

For instance, we write

const rem = bigInt("1738141852226360940").mod("32").valueOf();
console.log(rem);

to call the bigInt function with a string with the integer we want to define.

Then we call mod to return the modulo of the bigint when divided by 32.

And then we call valueOf to convert the returned value to an integer.

Conclusion

To define a JavaScript long integer, we can define a bigint.

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 *