Support for arbitrarily large integers (BigInts) is a stage 3 TC39 proposal. Stage 3 means the proposal is ready and for browsers to start implementing. Earlier this year, the V8 team added support for BigInts, which means Node.js 10.4.0 has BigInt support. You can use BigInts in Node.js 10.x without any flags, as long as you’re on at least 10.4.

$ ~/Workspace/libs/node-v10.4.0-linux-x64/bin/node --version
v10.4.0
$ ~/Workspace/libs/node-v10.4.0-linux-x64/bin/node
> 10000000000n * 10000000000n
100000000000000000000n
>

What Are BigInts?

BigInt is a new JavaScript primitive type that can store arbitrarily large integers, like the Busy Beaver sequence or values of the Ackermann sequence. You can store arbitrarily large numbers as strings, but BigInts have the benefit of supporting arithmetic operators. In other words, you can add and multiply BigInts like you would normal numbers.

There are 2 ways to create a BigInt: either by appending ‘n’ at the end of an integer literal, or by using the BigInt() constructor:

42n; // This is a BigInt
BigInt('42'); // This is equivalent
BigInt(42); // Also works

BigInts are not numbers, they are a completely new type. They’re the first new primitive type added to JavaScript since Symbols in ES2015. In Node.js 10.4, the primitive data types are:

  • Boolean
  • Null
  • Undefined
  • Number
  • String
  • Symbol
  • BigInt

To check if a value is a BigInt, you can use the typeof operator.

#node #javascript #web-development #programming #developer

An Overview of BigInt in Node.js
2.65 GEEK