BigInt
The BigInt data type is a new feature in JavaScript that allows you to work with arbitrarily large integers. BigInts are useful in situations where regular JavaScript numbers (Number) are not precise enough to represent the required values. Here's an example:
const bigNumber = BigInt(123456789012345678901234567890);
console.log(bigNumber); // Output: 123456789012345678901234567890n
console.log(bigNumber + 1n); // Output: 123456789012345678901234567891n
console.log(bigNumber * 2n); // Output: 246913578024691357802469135780n
In the code above, we're using the BigInt function to create a BigInt with a very large integer value. We can perform arithmetic operations on BigInts just like regular numbers, but we need to use the n suffix to indicate that the value is a BigInt.
No comments:
Post a Comment