JavaScript BigInt
JavaScript BigInt
- JavaScript BigInt variables are used to store big integer values that are too big to be represented by a normal JavaScript Number.
JavaScript Integer Accuracy
- JavaScript integers are only accurate up to 15 digits.
Sample Code
Output
- In JavaScript, all numbers are stored in a 64-bit floating-point format (IEEE 754 standard).
- With this standard, large integer cannot be exactly represented and will be rounded.
- Because of this, JavaScript can only safely represent integers.
- Up to 9007199254740991 +(253-1) and Down to -9007199254740991 -(253-1).
- Integer values outside this range lose precision.
How to Create a BigInt
- To create a BigInt, append n to the end of an integer or call BigInt().
Sample Code
Output
BigInt is the second numeric data type in JavaScript (after Number).
- With BigInt the total number of supported data types in JavaScript is 8.
- String
- Number
- Bigint
- Boolean
- Undefined
- Null
- Symbol
- Object