Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH RUST

JavaScript Basic

JS HOME JS Introduction JS Where To JS Output JS Syntax JS Statements JS Comments JS Variables JS Data Types JS Let JS Const JS Operators JS Arithmetic JS Assignment JS Functions JS Objects JS Events JS Strings JS String Templates JS Numbers JS Arrays JS Dates JS Math JS Booleans JS Comparisons JS Logical JS If Else JS Switch JS Loops JS Break JS Continue JS Errors JS Scope JS Code Blocks JS UTF-8 Characters

JS Advanced

JS Versions JS Statements JS Data Types JS String Methods JS Number Methods JS Date Formats JS Array Methods JS Functions JS Objects JS Classes JS Sets JS Maps JS Loops JS RegExp JS Callbacks JS Strict Mode JS DOM JS Window JS Web API JS AJAX JS JSON JS jQuery JS Graphics JS Examples

JS References

JavaScript Objects


JavaScript 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:

Integer Precision

let x = 999999999999999;
let y = 9999999999999999;
Try it Yourself »

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)

and

Down to -9007199254740991 -(253-1).

Integer values outside this range lose precision.


How to Create a BigInt

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

Examples

let x = 9999999999999999;
let y = 9999999999999999n;
Try it Yourself »
let x = 1234567890123456789012345n;
let y = BigInt(1234567890123456789012345)
Try it Yourself »

BigInt: A new JavaScript Datatype

The JavaScript typeof a BigInt is "bigint":

Example

let x = BigInt(999999999999999);
let type = typeof x;
Try it Yourself »

BigInt is the second numeric data type in JavaScript (after Number).

With BigInt the total number of supported data types in JavaScript is 8:

1. String
2. Number
3. Bigint
4. Boolean
5. Undefined
6. Null
7. Symbol
8. Object


BigInt Operators

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

BigInt Multiplication Example

let x = 9007199254740995n;
let y = 9007199254740995n;
let z = x * y;
Try it Yourself »

Notes

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).


BigInt Decimals

A BigInt can not have decimals.

BigInt Division Example

let x = 5n;
let y = x / 2;
// Error: Cannot mix BigInt and other types, use explicit conversion.
let x = 5n;
let y = Number(x) / 2;
Try it Yourself »

BigInt Hex, Octal and Binary

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

BigInt Hex Example

let hex = 0x20000000000003n;
let oct = 0o400000000000000003n;
let bin = 0b100000000000000000000000000000000000000000000000000011n;
Try it Yourself »

Precision Curiosity

Rounding can compromise program security:

MAX_SAFE_INTEGER Example

9007199254740992 === 9007199254740993; // is true !!!
Try it Yourself »

Browser Support

BigInt() is an ES2020 feature.

ES2020 is fully supported in all modern browsers since September 2020:

Chrome
85
Edge
85
Firefox
79
Safari
14
Opera
71
Aug 2020 Aug 2020 Mar 2020 Sep 2020 Sep 2020



×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.