Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende BigInt 2/3 | Data Types and Variables
Introduction to JavaScript

book
BigInt 2/3

BigIntwith Math Operators

We can use most of the math operators with BigInt just like we do with numbers, for example.

console.log(11n + 22n);
1
console.log(11n + 22n);
copy

A BigInt number and a regular number cannot be used together for performing some arithmetic operations, for example.

console.log(100n + 200);
1
console.log(100n + 200);
copy

For this, we have to convert the number into a BigInt number explicitly by calling the BigInt(), for example.

let bigint = 100n;
let number = 200;
console.log(bigint + BigInt(number));
123
let bigint = 100n; let number = 200; console.log(bigint + BigInt(number));
copy
Tarea

Swipe to start coding

A BigInt number named bigNumber with the assigned value of 12345n has been given to you. Your task is to:

  • Create a new variable named number and store 55 in it.
  • Convert the number to a BigInt number using the BigInt() function and store the result again in number.
  • Display the sum of these values.

Solución

let bigNumber = 12345n;
let number = 55;
number = BigInt(number);
console.log(bigNumber + number);

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 25
let bigNumber = 12345n;

Pregunte a AI

expand
ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

some-alt