This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// максимально возможное значение типа `BigInt`, | |
// которое может быть представлено как знаковое 64-битное целое число. | |
const max = 2n ** (64n - 1n) - 1n; | |
view[0] = max; | |
view[0]; | |
// → 9_223_372_036_854_775_807n | |
view[0] = max + 1n; | |
view[0]; | |
// → -9_223_372_036_854_775_808n | |
// ^ значение отрицательное, так как произошло переполнение |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// аксимально возможное значение типа `BigInt`, | |
// которое может быть представлено как знаковое 64-битное целое число. | |
const max = 2n ** (64n - 1n) - 1n; | |
view[0] = max; | |
view[0]; | |
// → 9223372036854775807n | |
view[0] = max + 1n; | |
view[0]; | |
// → -9223372036854775808n | |
// ^ значение отрицательное, так как произошло переполнение |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const view = new BigInt64Array(4); | |
// → [0n, 0n, 0n, 0n] | |
view.length; | |
// → 4 | |
view[0]; | |
// → 0n | |
view[0] = 42n; | |
view[0]; | |
// → 42n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Максимально возможное значение типа `BigInt`, | |
// которое может быть представлено как знаковое 64-битное целое число. | |
const max = 2n ** (64n - 1n) - 1n; | |
BigInt.asIntN(64, max); | |
// → 9223372036854775807n | |
BigInt.asIntN(64, max + 1n); | |
// → -9223372036854775808n | |
// ^ значение отрицательное, так как произошло переполнение |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BigInt(123); | |
// → 123n | |
BigInt(1.5); | |
// → RangeError | |
BigInt('1.5'); | |
// → SyntaxError |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 + 1n; | |
// → TypeError | |
123 < 124n; | |
// → true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BigInt(Number.MAX_SAFE_INTEGER) + 2.5; | |
// → ?? 🤔 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(7 + 6 - 5) * 4 ** 3 / 2 % 3; | |
// → 1 | |
(7n + 6n - 5n) * 4n ** 3n / 2n % 3n; | |
// → 1n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (0n) { | |
console.log('if'); | |
} else { | |
console.log('else'); | |
} | |
// → выведет 'else', так как `0n` преобразовано к false. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42n === BigInt(42); | |
// → true | |
42n == 42; | |
// → true |