) ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt) function
(without the ` new ` operator) and giving it an integer value or string value.

js

    
    
    const previouslyMaxSafeInteger = 9007199254740991n;
    
    const alsoHuge = BigInt(9007199254740991);
    // 9007199254740991n
    
    const hugeString = BigInt("9007199254740991");
    // 9007199254740991n
    
    const hugeHex = BigInt("0x1fffffffffffff");
    // 9007199254740991n
    
    const hugeOctal = BigInt("0o377777777777777777");
    // 9007199254740991n
    
    const hugeBin = BigInt(
      "0b11111111111111111111111111111111111111111111111111111",
    );
    // 9007199254740991n
    

BigInt values are similar to Number values in some ways, but also differ in a
few key matters: A BigInt value cannot be used with methods in the built-in [
` Math ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math) object
and cannot be mixed with a Number value in operations; they must be coerced to
the same type. Be careful coercing values back and forth, however, as the
precision of a BigInt value may be lost when it is coerced to a Number value.

###  Type information

When tested against ` typeof ` , a BigInt value ( ` bigint ` primitive) will
give ` "bigint" ` :

js

    
    
    typeof 1n === "bigint"; // true
    typeof BigInt("1") === "bigint"; // true
    

A BigInt value can also be wrapped in an ` Object ` :

js

    
    
    typeof Object(1n) === "object"; // true
    

###  Operators

Most operators support BigInts, however most do not permit operands to be of
mixed types â both operands must be BigInt or neither:

  * [ Arithmetic operators ](/en-US/docs/Web/JavaScript/Reference/Operators#arithmetic_operators) : ` + ` , ` - ` , ` * ` , ` / ` , ` % ` , ` ** `
  * [ Bitwise operators ](/en-US/docs/Web/JavaScript/Reference/Operators#bitwise_shift_operators) : ` >> ` , ` << ` , ` & ` , ` | ` , ` ^ ` , ` ~ `
  * [ Unary negation ( ` - ` ) ](/en-US/docs/Web/JavaScript/Reference/Operators/Unary_negation)
  * [ Increment/decrement ](/en-US/docs/Web/JavaScript/Reference/Operators#increment_and_decrement) : ` ++ ` , ` -- `

The boolean-returning operators allow mixing numbers and BigInts as operands:

  * [ Relational operators ](/en-US/docs/Web/JavaScript/Reference/Operators#relational_operators) and [ equality operators ](/en-US/docs/Web/JavaScript/Reference/Operators#equality_operators) : ` > ` , ` < ` , ` >= ` , ` <= ` , ` == ` , ` != ` , ` === ` , ` !== `
  * [ Logical operators ](/en-US/docs/Web/JavaScript/Reference/Operators#binary_logical_operators) only rely on the [ truthiness ](/en-US/docs/Glossary/Truthy) of operands 

A couple of operators do not support BigInt at all:

  * [ Unary plus ( ` + ` ) ](/en-US/docs/Web/JavaScript/Reference/Operators/Unary_plus) cannot be supported due to conflicting usage in asm.js, so it has been left out [ in order to not break asm.js ](https://github.com/tc39/proposal-bigint/blob/master/ADVANCED.md#dont-break-asmjs) . 
  * [ Unsigned right shift ( ` >>> ` ) ](/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift) is the only bitwise operator that's unsupported, as every BigInt value is signed. 

Special cases:

  * Addition ( ` + ` ) involving a string and a BigInt returns a string. 
  * Division ( ` / ` ) truncates fractional components towards zero, since BigInt is unable to represent fractional quantities. 

js

    
    
    const previousMaxSafe = BigInt(Number.MAX_SAFE_INTEGER); // 9007199254740991n
    const maxPlusOne = previousMaxSafe + 1n; // 9007199254740992n
    const theFuture = previousMaxSafe + 2n; // 9007199254740993n, this works now!
    const multi = previousMaxSafe * 2n; // 18014398509481982n
    const subtr = multi - 10n; // 18014398509481972n
    const mod = multi % 10n; // 2n
    const bigN = 2n ** 54n; // 18014398509481984n
    bigN * -1n; // -18014398509481984n
    const expected = 4n / 2n; // 2n
    const truncated = 5n / 2n; // 2n, not 2.5n
    

###