JavaScript
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax and Types
-
Section 3: Strings and Numbers in Depth
-
Section 4: Control Flow
-
Section 5: Functions
-
Section 6: Objects and Arrays
-
Section 7: Maps, Sets, and Symbols
-
Section 8: Asynchronous JavaScript
-
Section 9: Object-Oriented and Prototypes
-
Section 10: The DOM
-
Section 11: Browser APIs
-
Section 12: Modern JavaScript (ES2015-ES2025)
-
Section 13: Functional Programming Patterns
-
Section 14: Error Handling and Debugging
-
Section 15: Testing
-
Section 16: Accessibility for JavaScript Developers
-
Section 17: Internationalization and Localization
-
Section 18: Performance
-
Section 19: Node.js Fundamentals
-
Section 20: Regular Expressions
-
Section 21: Design Patterns in JavaScript
-
Section 22: Security Basics
-
Section 23: Data Structures and Algorithms in JavaScript
-
Section 24: Practical Projects
-
Section 25: More Advanced Async Patterns
-
Section 26: More Object and Class Practice
-
Section 27: Working with Dates and Internationalization
-
Section 28: Web Components
-
Section 29: More DOM and Browser Practice
-
Section 30: Build Tooling for Vanilla JavaScript
-
Section 31: More Practice Projects
-
Section 32: Interview and Algorithm Practice
-
Section 33: Error Objects (MDN Reference)
-
Section 34: TypedArrays and Binary Data
-
Section 35: Reflection and Metaprogramming (MDN Reference)
-
Section 36: More Global Functions (MDN Reference)
104: Numeric Separators and BigInt
Wait, why can't I just use a regular number for everything?
You might be wondering why we even need a separate BigInt type. For a long time, JavaScript only had the Number type, which uses 64-bit floats. That's great for decimals, but it has a ceiling for integers called Number.MAX_SAFE_INTEGER (which is 9,007,199,254,740,991).
If you try to go beyond that, JavaScript starts losing precision. It's not that the program crashes; it's worse—it just starts rounding your numbers, and your math becomes wrong. Imagine you're building a system to track snowflake IDs or huge blockchain transaction hashes. A tiny rounding error there is a disaster.
const max = Number.MAX_SAFE_INTEGER;
console.log(max + 1); // 9007199254740992
console.log(max + 2); // 9007199254740992 <-- Wait, what? Same result.
By adding an n to the end of the number, you tell JavaScript to treat it as a BigInt, allowing it to grow as large as your computer's memory allows.
How do I actually use BigInts without breaking my code?
The most important thing to remember is that BigInt and Number are different types, and JavaScript refuses to let you mix them in the same operation. If you try to add a BigInt to a regular Number, the engine will throw a TypeError. I've spent way too much time debugging this exact mistake.
You have to be explicit. If you want to do math with both, you need to convert one of them.
const bigAmount = 1000000000000000000n;
const taxRate = 5;
// This will throw an error:
// const total = bigAmount + taxRate;
// Do this instead:
const total = bigAmount + BigInt(taxRate);
console.log(total); // 1000000000000000005n
Are those underscores in numbers actually doing something?
No, they aren't doing anything to the logic—they're purely for your sanity. These are called Numeric Separators. When you're staring at a number like 1000000000, you have to stop and manually count the zeros to figure out if it's a hundred million or a billion. It's a waste of mental energy.
You can use the underscore _ as a visual comma. JavaScript completely ignores them when the code runs.
// These are identical to the engine:
const oldWay = 1000000000;
const cleanWay = 1_000_000_000;
// You can even use them with BigInts
const hugeNumber = 9_007_199_254_740_991n;
I highly recommend using these whenever you have a constant larger than four or five digits. It makes your code much more readable for the next person (which is usually you in six months).
📋 Practical Task
Exercise: Intergalactic Distance Calculator
You are writing a script to calculate the distance from Earth to a distant star system in meters. Because the distances are astronomical, you must use BigInt to avoid precision loss.
- Create a constant called
LIGHT_YEAR_METERSand assign it the value of9_460_730_472_580_800n. - Create a variable
distanceInLightYearsand set it to4_2n(representing Proxima Centauri). - Calculate the total distance in meters by multiplying these two values and store it in a constant called
totalDistance. - Create a regular
Numbervariable calledadjustmentFactorand set it to100. - Add the
adjustmentFactorto thetotalDistance(remember to cast theNumberto aBigIntfirst). - Log the final result to the console.
There are no comments for now.