Loading lesson path
Concept visual
Start from A
BigInt is a JavaScript data type for handling and storing big integer values. BigInt allows you to work with integers larger than the limit of Numbers. BigInt can represent an integer of any size, limited only by available memory.
JavaScript Numbers are only accurate up to 15 digits:
// 15 digits:
let x = 999999999999999;// 16 digits:
let y = 9999999999999999;Formula
Numbers are 64 - bits Floating PointFormula
64 - bit floating - point format (IEEE 754 standard).With this standard, large numbers cannot be exactly represented, but will be rounded. JavaScript can only safely represent integers up to
53 -1 (9007199254740991). JavaScript can only safely represent integers down to -2 53 -1 (-9007199254740991).
// MAX = 9007199254740991 let x = Number.MAX_SAFE_INTEGER;
// MIN = -9007199254740991 let y = Number.MIN_SAFE_INTEGER;Number.MAX_SAFE_INTEGER will lose precision: // Max (accurate)
let x = 9007199254740991;Formula
// Max + 10 (inaccurate)let y = x + 10;Number.MIN_SAFE_INTEGER will lose precision: // Min (accurate)
let x = -9007199254740991;Formula
// Min - 10 (inaccurate)let y = x - 10;There is no such thing as a JavaScript Integer.
Formula
All JavaScript Numbers are 64 - bit floating point.You can create a BigInt in two ways:
suffix
constructor with a string
// Using an integer literal with an n suffix:
let x = 999999999999999n;
// Using the BigInt() constructor with a string:
let y = BigInt("999999999999999");
let x = 12345678901234567890n;
let y = BigInt("12345678901234567890")
You can also create a BigInt using the Bigint() constructor with aNumber. Warning !! Numbers are only accurate up to 15 digits.
Examples let x = BigInt(9999999999999999);BigInt is "bigint":
let x = BigInt(999999999999999);
let type = typeof x;BigInt is the second numeric data type in JavaScript (after
).
BigInt the total number of supported data types in JavaScript is 8:
BigInt supports standard JavaScript arithmetic operators. (+, -, ++, --, *, /, %, **)
let x = 9007199254740995n;
let y = 9007199254740995n;
let z = x * y;Number is not allowed (will result in a