Curriculum
Module 39 // Core JavaScript
Intl API
Module Objective
Localization, number and date formatting
Mental Model Realtime Simulation
INTERACTIVE_CANVASEditor_Pane
Loading...
Console_Output
Waiting for output...
Practical Code Examples
// Example 1
// 1. Currency Formatting
const price = 1234.56;
const usFormat = new Intl.NumberFormat('en-US', {
style: 'currency', currency: 'USD'
}).format(price);
const inFormat = new Intl.NumberFormat('en-IN', {
style: 'currency', currency: 'INR'
}).format(price);
console.log(usFormat); // "$1,234.56"
console.log(inFormat); // "₹1,234.56"💡 `Intl.NumberFormat` handles decimal points, thousands separators, and currency symbols automatically based on the locale.
// Example 2
// 2. Full Date/Time
const now = new Date();
const formatter = new Intl.DateTimeFormat('fr-FR', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
});
console.log(formatter.format(now)); // "mercredi 17 décembre 2025"💡 Instead of complex regex or string hacking, `Intl` provides native, performant translation of date components.
// Example 3
// 3. Relative Time
const rtf = new Intl.RelativeTimeFormat('en', { style: 'short' });
console.log(rtf.format(-1, 'day')); // "1 day ago"
console.log(rtf.format(5, 'minute')); // "in 5 min."💡 Relative time formatting is perfect for social media apps or news feeds where 'just now' or '2 days ago' is more useful than a raw date.
Engine & Memory Architecture
The Localization Engine
1. Heavy Built-in:
- The
Intlobject is a massive subsystem in the engine. - It relies on the ICU (International Components for Unicode) library, which is a large binary stored in your browser's installation directory.
2. Formatting Performance:
- Creating an
Intlformatter object is relatively expensive in terms of CPU cycles. - Performance Tip: If you're formatting thousands of numbers in a loop, create the formatter once and reuse it (
const f = new Intl...) instead of creating a new one inside the loop.
3. Locale Data:
- Locales are loaded from RAM only when requested. The engine optimizes memory by keeping only the most common locale data resident.