Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

JS BigInt

JavaScript Integer Accuracy

In JavaScript, integers are accurate only up to 15 digits.

Integer Precision

let x = 999999999999999;
let y = 9999999999999999;

JavaScript stores all numbers in a 64-bit floating-point format based on the IEEE 754 standard. Due to this standard, large integers may not be precisely represented and can be rounded.

JavaScript can accurately represent integers within the range of -9007199254740991-(253-1) to 9007199254740991+(253-1).

Integer values beyond this range may lose precision due to the limitations of the floating-point format.

How to Create a BigInt

To create a BigInt, you can either append “n” to the end of an integer or use the BigInt() function:

Example

let x = 9999999999999999;
let y = 9999999999999999n;

Example

let x = 1234567890123456789012345n;
let y = BigInt(1234567890123456789012345)

BigInt: A new JavaScript Datatype

The typeof a BigInt in JavaScript is “bigint”.

let x = BigInt(999999999999999);
let type = typeof x;

BigInt is the second numeric data type in JavaScript, following Number.

With BigInt, the total number of supported data types in JavaScript reaches 8:

  1. String
  2. Number
  3. BigInt
  4. Boolean
  5. Undefined
  6. Null
  7. Symbol
  8. Object