15

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.

Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75
Nikola Dim
  • 736
  • 7
  • 21

1 Answers1

13

From BigInt on MDN:

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.

mikemaccana
  • 110,530
  • 99
  • 389
  • 494
Nikola Dim
  • 736
  • 7
  • 21
  • 4
    I couldn't find any info on what the `n` stands for. Is it arbitrary, or has some precedent in CS? – dwelle Jun 13 '20 at 15:18
  • 4
    [This thread](https://github.com/tc39/proposal-bigint/issues/1) would suggest it's arbitrary (although not 100% certain). – dwelle Jun 13 '20 at 15:28