I've seen
const num = 123456789000000000000n;
And don't know what the n at the end of numeric literal does?
At the time of writing, when searching online for "What does character 'n' after numeric literal mean in JavaScript" nothing comes up.
A natural number is a number that occurs commonly and obviously in nature. As such, it is a whole, non-negative number. The set of natural numbers, denoted N, can be defined in either of two ways: N = {0, 1, 2, 3, ...}
A BigInt value, also sometimes just called a BigInt, is a bigint primitive, created by appending n to the end of an integer literal, or by calling the BigInt() function (without the new operator) and giving it an integer value or string value.
The following rules govern the formation of numeric literals: A literal must contain at least one digit. A literal must contain no more than one sign character and, if one is used, it must be the leftmost character of the string. A literal must not contain more than one decimal point.
Number is a primitive wrapper object used to represent and manipulate numbers like 37 or -9.25 . The Number constructor contains constants and methods for working with numbers. Values of other types can be converted to numbers using the Number() function.
From MDN (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
A BigInt is created by appending n to the end of an integer literal — 10n — or by calling the function BigInt().
In essence, BigInt allows for storing large integers, as otherwise a large numeric literal would be converted into a floating point and lose precision of the least significant digits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With