Course contentsShow
← JavaScript
Lesson 1965 of 2,72341. Modern JavaScript Features (ES2020+)Free lesson

Numeric Separators in Different Bases

Apply numeric separators to binary, octal, and hexadecimal literals, not just decimals.

Numeric Separators in Different Bases

What you'll learn: How to use underscores to make binary, octal, and hexadecimal literals more readable, just like you can with decimal numbers.

In the previous lesson, you learned that numeric separators (_) make large decimal numbers easier to read. But JavaScript doesn't limit this feature to base-10 numbers—you can use underscores in binary (0b), octal (0o), and hexadecimal (0x) literals too.

This is especially helpful when working with bit flags, color codes, or low-level programming where these bases are common.

Binary with Separators

// Without separators - hard to parse visually
const permissions = 0b11010110;

// With separators - grouped by nibbles (4 bits)
const readablePermissions = 0b1101_0110;

console.log(permissions === readablePermissions); // true

Hexadecimal with Separators

// Color codes become clearer
const color = 0xFF_6B_4A; // RGB: FF (red), 6B (green), 4A (blue)

// Memory addresses
const address = 0xDEAD_BEEF;

Octal with Separators

// Unix file permissions
const fileMode = 0o755; // Small enough, but you could do 0o7_5_5

The separator placement is entirely up to you—JavaScript ignores them during parsing. They're purely visual aids. Group them in whatever way makes the most sense for your use case (nibbles, bytes, RGB components, etc.).

Key Takeaway: Numeric separators work in binary (0b), octal (0o), and hexadecimal (0x) literals, making bit patterns, color codes, and low-level values much easier to read and maintain.