Big Ints 18 Flashcards

1
Q

Why were bigints added in ECMAScript2020?

A

Before, js could only suppost ~53 bits. Anything larger would have to be stored in a string.

Bigints are used widely in fin tech. They multiply (internally) by 100 to get rid of the cents.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are big ints?

A

New primitive data type for Numbers without a fixed storage size, they adapt to the integers they represent.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which bases do bigint literals support?

A

Decimal: 123n
Hexadecimal: 0xFFn
Binary: 0b1101n
Octal: 0o777n

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

With most operators, we are not allowed to mix bigints and numbers. If we do exceptions are thrown. How come?

A

Bc there is no general way of coercing a number and a bigint to a common type. Numbers can’t represent bigints beyond 53 bits and bigints can’t represent fractions.

However, you can compare bigints and numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Can you serialize a bigint? hint: JSON.stringify(1n)

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How does one decide to use numbers vs bigints?

A

Use numbers for up to 53 bits and for Array indices. Rationale: they already appear everywhere and are handled efficiently by most engines (especially if they fit into 32 bits)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly