Loading Please Wait...

Logo Lynxsia IT Solutions

JavaScript BigInt

JS BigInt

JavaScript BigInt variables are used to store big integer values that are too big to be represented by a normal JavaScript Number.

JavaScript Integer Accuracy

JavaScript integers are only accurate up to 15 digits.

					 
        
          let a = 999999999999999;
          let b = 9999999999999999;
        
      

In JavaScript, all numbers are stored in a 64-bit floating-point format (IEEE 754 standard).

With this standard, large integer cannot be exactly represented and will be rounded.

Because of this, JavaScript can only safely represent integers

Up to 9007199254740991 +(253-1)

Down to -9007199254740991 -(253-1).

Integer values outside this range lose precision.

Create a BigInt

To create a BigInt, append n to the end of an integer or call BigInt():

					 
        
          let a = 1234567890123456789012345n;
          let b = BigInt(1234567890123456789012345)
          typeof a // returns bigint
        
      
BigInt Operators

Operators that can be used on a JavaScript Number can also be used on a BigInt.

					 
        
          let a = 9007199254740995n;
          let b = 9007199254740995n;
          let c = a + b;
          let d = a - b;
          let e = a * b;
        
      
BigInt Hex, Octal and Binary

BigInt can also be written in hexadecimal, octal, or binary notation:

					 
        
          let hex = 0x20000000000003n;
          let oct = 0o400000000000000003n
          let bin = 0b100000000000000000000000000000000000000000000000000011n;
        
      
Arithmetic between a BigInt and a Number is not allowed (type conversion lose information).
Unsigned right shift (>>>) can not be done on a BigInt (it does not have a fixed width).
A BigInt can not have decimals.

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved