BigInt
BigInt は、大きすぎてまたは小さすぎて数値 (number) プリミティブで表すことができない数を表現します。
対応ブラウザ
| 機能 | デスクトップ | モバイル | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 67 | 79 | 68 | 14 | 67 | 14 | |
| BigInt() コンストラクターは長整数型の値を返します。 | 67 | 79 | 68 | 14 | 67 | 14 |
| BigInt.asIntN は静的メソッドで、長整数を符号付き整数値に丸め、その値を返します。 | 67 | 79 | 68 | 14 | 67 | 14 |
| BigInt.asUintN() は静的メソッドで、長整数を符号なし整数に丸め、その値を返します。 | 67 | 79 | 68 | 14 | 67 | 14 |
| toString() は BigInt 値のメソッドで、指定した長整数 (BigInt) 値を表す文字列を返します。末尾の "n" は文字列の一部にはなりません。 | 67 | 79 | 68 | 14 | 67 | 14 |
| valueOf() は BigInt 値のメソッドで、 BigInt オブジェクトにラップされているプリミティブ値を返します。 | 67 | 79 | 68 | 14 | 67 | 14 |
基本構文
JAVASCRIPT
const big = 9007199254740993n; // Cannot be represented as a Number
const sum = big + 1n; // 9007199254740994n
typeof big; // 'bigint'
// Cannot perform mixed operations with Number
// big + 1; // TypeError
BigInt(42) + big; // OK ライブデモ
large number. Accurate calculation
Number large number, BigInt Useaccurate to calculation..
プレビュー全画面表示
Precisioncomparison(number vs Bigint)
is accurate to and comparison.. with is errordifference that outcalculation, BigInt. with Number
プレビュー全画面表示
実務での使いどころ
-
BigInt の活用
BigInt は、大きすぎてまたは小さすぎて数値 (number) プリミティブで表すことができない数を表現します。
注意点
- 特になし。すべての主要ブラウザで安定して動作する。
アクセシビリティ
- JavaScript による動的更新時は、aria-live リージョンで変更をスクリーンリーダーに通知する。