Intl is the built-in internationalization API (ECMA-402). Each constructor takes (locales, options) and returns a formatter with format() (and often formatToParts()); toLocaleString() and friends are shortcuts that build one internally.
| API | Job | Key options |
|---|---|---|
DateTimeFormat |
dates and times | dateStyle, timeStyle, or fields (year, hour, …); timeZone; hourCycle; timeZoneName |
NumberFormat |
numbers | style: 'currency' | 'percent' | 'unit', currency, unit, notation: 'compact', maximumFractionDigits |
PluralRules |
which plural category a number takes | type: 'cardinal' | 'ordinal' |
RelativeTimeFormat |
"in 2 weeks", "yesterday" | numeric: 'always' | 'auto', style |
ListFormat |
"a, b, and c" | type: 'conjunction' | 'disjunction' | 'unit' |
What interviewers look for:
- Do not hand-roll patterns. Field order, separators, digits, currency placement and list grammar all vary by locale, and
Intlgets them from CLDR data. - The time zone is separate from the locale.
DateTimeFormatuses the host's zone unless you pass an IANAtimeZone. Formatting server-side without one gives different strings on different machines. - Plurals are categories, not
n === 1. English hasone/other; Polish hasone/few/many/other; Arabic has six. Select a category and map it to a message. dateStyle/timeStylecannot be mixed with field options such ashour. V8 throws aTypeErrorat construction.hour12overrideshourCycle.- Reuse formatters. Construction loads locale data. Build once at module level or memoize per locale and options.
- Output is data-dependent. The same call can differ across engines and ICU/CLDR versions, so never parse formatted strings or assert on them in cross-environment tests.