Numeric Separators for Readability
What you'll learn: How to use underscores in numeric literals to make large numbers easier to read at a glance.
The Problem with Large Numbers
When you're working with large numeric values in code, they can become difficult to parse visually:
const budget = 1000000000; // Is this a billion? Let me count...
const bytes = 1073741824; // No idea what this is
Your brain has to count digits to understand the magnitude, which is error-prone and slows you down.
Enter Numeric Separators
ES2021 introduced numeric separators — the underscore character (_) that you can place between digits in numeric literals. JavaScript ignores these underscores completely during execution; they exist purely for human readability:
const budget = 1_000_000_000; // Clearly one billion
const bytes = 1_073_741_824; // 1 GB in bytes
const creditCard = 1234_5678_9012_3456; // Card number format
const binary = 0b1010_0001_1000_0001; // Binary in byte chunks
const hex = 0xFF_EC_DE_5E; // Hex in byte pairs
How It Works
Think of numeric separators like commas in handwritten numbers — they're visual aids that group digits into meaningful chunks. The actual numeric value remains identical:
console.log(1000000 === 1_000_000); // true
console.log(0.000001 === 0.000_001); // true
You can use them in integers, floats, binary, octal, and hexadecimal literals. Place them wherever makes sense for your domain — financial amounts might use thousands separators, while binary might chunk by 4 or 8 bits.
Key Takeaway: Numeric separators (_) are purely cosmetic underscores that make large numeric literals more readable without affecting their actual value — use them to visually group digits in whatever pattern makes the number easiest to understand.