-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
The BigInt
type was introduced in ES2020 to safely represent integers larger than 2^53 - 1
, which is the limit of the Number
type in JavaScript.
JavaScript’s regular Number
type uses 64-bit floating-point representation, which cannot accurately represent integers larger than 2⁵³ - 1 (9007199254740991).
console.log(Number.MAX_SAFE_INTEGER); // 9007199254740991
console.log(9007199254740991 + 1); // 9007199254740992 ✅
console.log(9007199254740991 + 2); // 9007199254740992 ❌ (wrong!)
n
suffix:let big = 1234567890123456789012345678901234567890n;
BigInt()
constructor:let big2 = BigInt("1234567890123456789012345678901234567890");
let a = 10n;
let b = 20n;
let sum = a + b; // 30n
let diff = b - a; // 10n
let prod = a * b; // 200n
let div = b / a; // 2n (no decimal!)
let mod = b % a; // 0n
📌 Note: Division always returns the integer part (no decimal points).
let big = 10n;
let num = 10;
console.log(big + num); // ❌ TypeError: Cannot mix BigInt and other types
✅ You must explicitly convert:
let total = big + BigInt(num);
10n === 10 // false (different types)
10n == 10 // true (values are equal)
typeof 10n; // "bigint"
Q1. How do you declare a BigInt value 12345678901234567890123n
and store it in a variable named largeNumber
?
Q2. How do you create a BigInt using the BigInt()
function with a string value?
Q3. What is the output of adding two BigInts 100n
and 200n
?
Q4. How do you subtract 10n
from 25n
and store the result?
Q5. How do you divide 25n
by 4n
and what is the result?
Q6. How do you convert a regular number 100
into a BigInt before adding to 1000n
?
Q7. Why does mixing BigInt and Number directly in arithmetic cause a TypeError?
Q8. How do you find the type of a BigInt variable using typeof
?
Q9. How do you check whether 10n == 10
returns true or false and why?
Q10. How do you find the remainder when dividing 55n
by 6n
using the %
operator?
Q1: What is the type returned by typeof 123456789n?
Q2: Which of the following is a valid way to declare a BigInt?
Q3: What will be the result of 10n + 20?
Q4: What does BigInt("9999999999999999999999") return?
Q5: What is the output of 25n / 4n?
Q6: Which of the following operations is invalid with BigInt?
Q7: What will 10n == 10 return?
Q8: What will 10n === 10 return?
Q9: Which method can be used to convert 100 (Number) into BigInt?
Q10: What will be the result of typeof BigInt("100")?