--- id: javascript-bigint title: "JavaScript BigInt" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["BigInt", "arbitrary precision integer", "n suffix", "BigInt()", "ES2020 integers", "large integers"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.89 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["javascript", "js", "web", "frontend", "w3schools", "bigint", "number", "es2020"] raw_sources: ["https://www.w3schools.com/js/js_bigint.asp"] applied_in: [] github_commit: "" --- # [[JavaScript BigInt]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) `BigInt` is a JavaScript data type for whole numbers too large for the ordinary `Number` type β€” it represents integers of arbitrary size (limited only by memory), but cannot hold decimals and cannot be freely mixed with `Number` values. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Purpose** β€” `BigInt` handles integers larger than the safe-integer limits of the `Number` type, representing integers of any size constrained only by available memory. [S1] - **Why it exists** β€” JavaScript Numbers are 64-bit floating point (IEEE 754) and only accurate up to 15 digits; safe integers run from `9007199254740991` (`2⁡³ βˆ’ 1`) down to `-9007199254740991`. [S1] - **Two creation forms** β€” an integer literal with an `n` suffix, or the `BigInt()` constructor (from a string or a Number). [S1] - **It is a distinct type** β€” `typeof` a BigInt is `"bigint"`; it is the third numeric-family data type, making eight JavaScript types in total. [S1] - **No mixing without conversion** β€” arithmetic between a BigInt and a Number throws a `TypeError`; convert explicitly with `Number()` or `BigInt()`. [S1] - **No decimals** β€” a BigInt cannot have decimal values. [S1] - **ES2020 feature** β€” supported in modern browsers since September 2020. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **`n` literal vs constructor** β€” `999999999999999n` (literal) or `BigInt("999999999999999")` (string constructor avoids the 15-digit accuracy loss). [S1] - **Explicit cross-type conversion** β€” to combine with a Number, wrap one side: `Number(x) + y`. [S1] - **Loose vs strict equality** β€” `10n == 10` is `true`, but `10n === 10` is `false` because the types differ. [S1] - **No `>>>` on BigInt** β€” unsigned right shift is not allowed with BigInts. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **What is JavaScript BigInt?** β€” `BigInt` is a data type that can represent integers of any size, limited only by available memory. [S1] **JavaScript Accuracy / Numbers are 64-bits Floating Point** β€” JavaScript Numbers are only accurate up to 15 digits and use 64-bit floating-point format (IEEE 754). The safe integer range is `9007199254740991` (`2⁡³ βˆ’ 1`) to `-9007199254740991` (`βˆ’(2⁡³ βˆ’ 1)`). [S1] ```javascript // 15 digits: let x = 999999999999999; // 16 digits: let y = 9999999999999999; ``` ```javascript // MAX = 9007199254740991 let x = Number.MAX_SAFE_INTEGER; // MIN = -9007199254740991 let y = Number.MIN_SAFE_INTEGER; ``` ```javascript // Max (accurate) let x = 9007199254740991; // Max + 10 (inaccurate) let y = x + 10; ``` **How to Create a BigInt** β€” use an integer literal with an `n` suffix, or the `BigInt()` constructor: [S1] ```javascript // Using an integer literal with an n suffix: let x = 999999999999999n; // Using the BigInt() constructor with a string: let y = BigInt("999999999999999"); ``` **BigInt is a JavaScript Datatype** β€” `typeof` returns `"bigint"`: [S1] ```javascript let x = BigInt(999999999999999); let type = typeof x; ``` BigInt is the third numeric data type. The eight JavaScript data types are: String, Number, Bigint, Boolean, Undefined, Null, Symbol, Object. [S1] **Arithmetic Operators** β€” BigInt supports `+`, `-`, `++`, `--`, `*`, `/`, `%`, `**`: [S1] ```javascript let x = 9007199254740995n; let y = 9007199254740995n; let z = x * y; ``` **Mixing BigInt and Numbers** β€” mixing throws a `TypeError`; convert explicitly: [S1] ```javascript let x = 10n; let y = 5; let z = x + y; // ❌ TypeError ``` ```javascript let x = 10n; let y = 5; let z = Number(x) + y; ``` **BigInt / Number Conversions** β€” BigInt to Number with `Number(value)`, Number to BigInt with `BigInt(value)`; large conversions may result in Infinity or precision loss. [S1] **BigInt Decimals** β€” a BigInt cannot have decimals, and mixing with division throws an error: [S1] ```javascript let x = 5n; let y = x / 2; // ❌ Error: Cannot mix BigInt and other types, use explicit conversion. ``` **Comparison Operators** β€” BigInt supports `<`, `>`, `==`, `===`, `!==`, `<=`, `>=`. Strict equality between a BigInt and a Number is always false: [S1] ```javascript // true let x = (10n > 5n); // false (different types) let y = (10n === 10); // true (loose equality) let z = (10n == 10); ``` **Bitwise Operators** β€” BigInt supports `&`, `|`, `^`, `~`: [S1] ```javascript let a = 5n; // 0101 let b = 3n; // 0011 let x = (a & b); // 1n (0001) let y = (a | b); // 7n (0111) let z = (a ^ b); // 6n (0110) let n = (~a); // -6n ``` **Bitwise Shift Operators** β€” BigInt supports `<<` and `>>`. Unsigned right shift (`>>>`) is not allowed with BigInts: [S1] ```javascript let big = 10n; // binary: 1010 let x = (big << 2n); // 40n (101000) let y = (big >> 1n); // 5n (0101) ``` **BigInt Hex, Octal and Binary** [S1] ```javascript let num = 256n; let oct = 0o400n; let hex = 0x100n; let bin = 0b100000000n; ``` **Precision Curiosity** β€” Number rounding makes two distinct large integers compare equal, while BigInt keeps them distinct: [S1] ```javascript 9007199254740992 === 9007199254740993; // is true !!! ``` ```javascript 9007199254740992n === 9007199254740993n; // is false !!! ``` **Summary** β€” BigInt enables arbitrary-precision integer arithmetic. Limitations: no decimal support, incompatibility with `Math` functions, and `JSON.stringify()` cannot handle BigInts. [S1] **Browser Support** β€” BigInt is an ES2020 feature, fully supported in modern browsers since September 2020. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's own snippets are the canonical applied examples β€” creating BigInts via the `n` literal and the `BigInt()` constructor, multiplying large values, the explicit `Number(x) + y` conversion, and the precision-comparison curiosity. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Create a BigInt (language: JavaScript): ```javascript let a = 999999999999999n; let b = BigInt("999999999999999"); ``` Mix safely with a Number via explicit conversion: ```javascript let x = 10n; let y = 5; let z = Number(x) + y; ``` Compare with loose vs strict equality: ```javascript 10n == 10; // true 10n === 10; // false ``` ## βš–οΈ 비ꡐ 및 선택 κΈ°μ€€ (Comparison & decision criteria) - **Use `Number`** for everyday math and any value within the safe-integer range (`Β±9007199254740991`) or requiring decimals. [S1] - **Use `BigInt`** when integers exceed the safe-integer range and must stay exact (the page cites cryptography, IDs, and timestamps), accepting that decimals, `Math` functions, and `JSON.stringify()` are unavailable. [S1] - **Never mix the two directly** β€” arithmetic across the types throws a `TypeError`; convert one side explicitly. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) No contradictions found in the source. ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.89 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[JavaScript Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[JavaScript Numbers]], [[JavaScript Number Properties]], [[JavaScript Bitwise]], [[JavaScript Data Types]] - **μ°Έμ‘° λ§₯락:** Referenced when exact large-integer arithmetic is required beyond the Number safe-integer limit. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” JavaScript BigInt β€” https://www.w3schools.com/js/js_bigint.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript BigInt" page (Astra wiki-curation, P-Reinforce v3.1 format).