13

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
  • 16,564
  • 7
  • 51
  • 69
Nikola Dim
  • 666
  • 5
  • 21

1 Answers1

11

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.

Nikola Dim
  • 666
  • 5
  • 21
  • 1
    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
  • 2
    [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