BigInt 2/3
BigIntwith Math Operators
We can use most of the math operators with BigInt just like we do with numbers, for example.
1console.log(11n + 22n);
A BigInt number and a regular number cannot be used together for performing some arithmetic operations, for example.
1console.log(100n + 200);
For this, we have to convert the number into a BigInt number explicitly by calling the BigInt(), for example.
123let bigint = 100n; let number = 200; console.log(bigint + BigInt(number));
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
numberand store55in it. - Convert the
numberto a BigInt number using theBigInt()function and store the result again innumber. - Display the sum of these values.
Løsning
Tak for dine kommentarer!
single
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat
Can you explain why BigInt and regular numbers can't be mixed in operations?
How do I convert a regular number to BigInt?
Are there any limitations when using BigInt with math operators?
Fantastisk!
Completion rate forbedret til 2
BigInt 2/3
Stryg for at vise menuen
BigIntwith Math Operators
We can use most of the math operators with BigInt just like we do with numbers, for example.
1console.log(11n + 22n);
A BigInt number and a regular number cannot be used together for performing some arithmetic operations, for example.
1console.log(100n + 200);
For this, we have to convert the number into a BigInt number explicitly by calling the BigInt(), for example.
123let bigint = 100n; let number = 200; console.log(bigint + BigInt(number));
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
numberand store55in it. - Convert the
numberto a BigInt number using theBigInt()function and store the result again innumber. - Display the sum of these values.
Løsning
Tak for dine kommentarer!
single