The Intl (Internationalization) object in JavaScript helps format data — numbers, dates, lists, and text — for specific locales.


💰 1. Number and Currency Formatting: Intl.NumberFormat

const amount = 1234567.89;
const jpy = new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' });
console.log(jpy.format(amount)); // ¥1,234,568


🕰 2. Date & Time Formatting: Intl.DateTimeFormat

const now = new Date();

const enUS = new Intl.DateTimeFormat('en-US', { dateStyle: 'full', timeStyle: 'long' });
console.log(enUS.format(now)); // Friday, July 21, 2025 at 7:05:00 PM GMT+05:30

🔤 3. Locale-Sensitive Sorting: Intl.Collator

const words = ['résumé', 'repertoire', 'resume'];
const deSort = new Intl.Collator('de-DE');
console.log(words.slice().sort(deSort.compare)); // German sorting

⏳ 4. Relative Time: Intl.RelativeTimeFormat

const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto', style: 'long' });
console.log(rtf.format(-1, 'day'));       // yesterday
console.log(rtf.format(-3, 'month'));     // 3 months ago
console.log(rtf.format(5, 'quarter'));    // in 5 quarters


🧾 5. List Composition: Intl.ListFormat

const items = ['Motorcycle', 'Bus', 'Car'];

const enList = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' });
console.log(enList.format(items)); // Motorcycle, Bus, and Car


📊 6. Pluralization Rules: Intl.PluralRules

const plural = new Intl.PluralRules('en-US');

console.log(plural.select(1));    // one
console.log(plural.select(2));    // other
console.log(plural.select(0.5));  // other