Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
64
rated 0 times [  66] [ 2]  / answers: 1 / hits: 6486  / 4 Years ago, sun, may 3, 2020, 12:00:00

I just came across JavaScript's new data type BigInt. What are some of the real-time use cases where we have to use BigInt vs Number?



I also see that it doesn't have cross-browser compatibility at this point.


More From » javascript

 Answers
6

MDN doc




BigInt is a built-in object that provides a way to represent whole
numbers larger than 2^53 - 1, which is the largest number JavaScript
can reliably represent with the Number primitive and represented by
the Number.MAX_SAFE_INTEGER constant. BigInt can be used for
arbitrarily large integers.




Difference:




  • BigInt cannot be used with methods in the built-in Math object and cannot be mixed with instances of Number in operations

  • Because coercing between Number and BigInt can lead to loss of
    precision, it is recommended to only use BigInt when values greater
    than 2^53 are reasonably expected and not to coerce between the two
    types.


[#3936] Thursday, April 30, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rylee

Total Points: 658
Total Questions: 114
Total Answers: 116

Location: Christmas Island
Member since Mon, Oct 19, 2020
4 Years ago
;