Big Ints 18 Flashcards
Why were bigints added in ECMAScript2020?
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.
What are big ints?
New primitive data type for Numbers without a fixed storage size, they adapt to the integers they represent.
Which bases do bigint literals support?
Decimal: 123n
Hexadecimal: 0xFFn
Binary: 0b1101n
Octal: 0o777n
With most operators, we are not allowed to mix bigints and numbers. If we do exceptions are thrown. How come?
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
Can you serialize a bigint? hint: JSON.stringify(1n)
No
How does one decide to use numbers vs bigints?
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)