Course contentsShow
← JavaScript
Lesson 2245 of 2,72346. InternationalizationFree lesson

Combining ListFormat with Other Intl APIs

See practical patterns for composing ListFormat with NumberFormat or DateTimeFormat output.

Combining ListFormat with Other Intl APIs

You'll learn how to compose Intl.ListFormat with NumberFormat and DateTimeFormat to create rich, naturally-flowing multilingual output.

The Power of Composition

While each Intl API excels at its specific task—numbers, dates, lists—the real magic happens when you combine them. Think of it like a recipe: NumberFormat gives you perfectly formatted ingredients (numbers), DateTimeFormat provides the timing (dates), and ListFormat assembles everything into a readable sentence.

Practical Patterns

Lists of Formatted Numbers

const formatter = new Intl.NumberFormat('en-US', {
  style: 'currency',
  currency: 'USD'
});

const prices = [19.99, 24.50, 9.99];
const formattedPrices = prices.map(p => formatter.format(p));

const list = new Intl.ListFormat('en-US', { style: 'long', type: 'conjunction' });
console.log(list.format(formattedPrices));
// "£19.99, $24.50, and $9.99"

Lists of Formatted Dates

const dateFormatter = new Intl.DateTimeFormat('en-US', { 
  month: 'long', 
  day: 'numeric' 
});

const events = [
  new Date(2024, 5, 15),
  new Date(2024, 5, 22),
  new Date(2024, 6, 4)
];

const formattedDates = events.map(d => dateFormatter.format(d));
const listFormatter = new Intl.ListFormat('en-US', { type: 'disjunction' });

console.log(listFormatter.format(formattedDates));
// "June 15, June 22, or July 4"

Why This Matters

By piping formatted output from NumberFormat or DateTimeFormat into ListFormat, you maintain full locale-awareness at every level. Each API handles its domain correctly, then ListFormat applies the culturally appropriate list conventions.

Key Takeaway: Combining Intl APIs creates composable, locale-aware pipelines—format your data with specialized APIs, then assemble the results naturally with ListFormat.