What is the maximum size of a variable of type int in Javascript?

Asked

Viewed 269 times

5

I intend to make an algorithm that creates prime numbers, and I need to know what the number limit is that I can have on a variable. If anyone can help me, thank you very much

2 answers

9


You can get this information through Number.MAX_SAFE_INTEGER.

const maxInteger = Number.MAX_SAFE_INTEGER;

console.log(`O maior número inteiro é ${maxInteger}`);

This value represents the number 253-1. If you need larger numbers than this you can use BigInt, which may be arbitrarily large, but take care of the support for it by the browsers.

  • How can I create a Bigint variaviel?

  • @XTRADEXTRADE There is a link to the documentation in the reply, there will have all the details of this type.

  • Oh it’s now I see, Thanks bro!

  • Okay but look I want to convert a number 2 777232937 and I want to write it in a txt

  • And it gives an error where it says it cannot convert an Infinity number to Bigint

  • @XTRADEXTRADE You can try doing 2n**777232937n if your computer holds up...

  • 2 to the 777232937 is a lot, man...

  • Yeah, I know, but you can do that, right?

  • Anderson, what’s the point of putting 'n' in the number ?

  • @XTRADEXTRADE Have this described in the documentation too, read there.

Show 5 more comments

4

The largest size of an integer is 9007199254740991, you can check using Number.MAX_SAFE_INTEGER

Browser other questions tagged

You are not signed in. Login or sign up in order to post.