BigInt in JavaScript

const bigint = 1234567890123456789012345678901234567890n;

const sameBigint = BigInt("1234567890123456789012345678901234567890");

const bigintFromNumber = BigInt(10); // same as 10n

Math operators

alert(1n + 2n); // 3alert(5n / 2n); // 2
alert(1n + 2); // Error: Cannot mix BigInt and other types
let bigint = 1n;
let number = 2;
// number to bigint
alert(bigint + BigInt(number)); // 3
// bigint to number
alert(Number(bigint) + number); // 3

The unary plus is not supported on Bigints

let bigint = 1n;alert( +bigint ); // error

Comparisons

alert( 2n > 1n ); // truealert( 2n > 1 ); // true
alert( 1 == 1n ); // truealert( 1 === 1n ); // false

Boolean operations

if (0n) {
// never executes
}
alert( 1n || 2 ); // 1 (1n is considered truthy)alert( 0n || 2 ); // 2 (0n is considered falsy)

--

--

--

Developer with 3 yrs of industrial experience in developing scalable web applications.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

ECMAScript Automatic Semicolon Insertion

Off With Their Heads: How to Build a Headless WordPress to Manage Content

React & Redux

React & Font Awesome Brand Icons

🌍 Creating React usePosition() hook for getting browser’s geolocation

Why you should build your own component library

Create a Countdown With Observables

Learn JavaScript from Scratch in 2022 (5.18)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhay Jain

Abhay Jain

Developer with 3 yrs of industrial experience in developing scalable web applications.

More from Medium

Javascript, my love/hate story

Special Concepts about JavaScript & MongoDB

Using JavaScript and window.postMessage() for Safe Cross-Domain Communication

Basics of JavaScript for technical interviews