← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

Intl API

JavaScript ES2015 Intermediate
debt(d5/e3/b3/t5)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches it' (d5). ESLint and TypeScript can detect hardcoded date format strings and missing locale parameters via linting rules, but detection is not automatic—requires configured rules and code review to catch patterns like `new Date().toLocaleDateString()` without locale or manual currency formatting with `.toFixed(2)`. Most misuses (caching formatters, choosing wrong unit for RelativeTimeFormat) require runtime testing or careful inspection.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix is to replace hardcoded formatting with `Intl.NumberFormat`, `Intl.DateTimeFormat`, or `Intl.RelativeTimeFormat` calls—typically a single-line or few-line substitution per occurrence. However, if the codebase has many hardcoded formats scattered across files, or if formatters are being reconstructed in loops (requiring caching refactors), effort scales up slightly. Most common cases stay within e3 range.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). The Intl API choice primarily affects formatting logic in UI components and output routines; it does not impose system-wide architectural constraints. Teams using it consistently pay a small productivity cost (learning the API surface, caching patterns, locale handling), but this burden is localized to i18n-aware modules. The rest of the codebase is unaffected by this choice.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap' (t5). The misconception—that you need an external library like moment.js or date-fns for proper localization—is documented and most developers eventually learn the Intl API is built-in. However, the API has several gotchas: forgetting to cache formatters (performance trap), not using `navigator.language` (silently defaults to en-US), omitting the `unit` parameter in RelativeTimeFormat (breaks), and overlooking `Intl.Collator` for string sorting (silent wrong order with accented characters). These are documented but require learning; they don't contradict similar concepts, making this a tier-5 rather than tier-7 trap.

About DEBT scoring →

Also Known As

Intl internationalisation i18n JavaScript NumberFormat DateTimeFormat

TL;DR

The built-in JavaScript internationalisation API — format numbers, dates, currencies, relative times, and lists correctly for any locale without external libraries.

Explanation

The Intl API provides: Intl.NumberFormat (numbers, currencies, percentages), Intl.DateTimeFormat (dates, times with locale-aware formatting), Intl.RelativeTimeFormat ('2 days ago', 'in 3 hours'), Intl.ListFormat ('A, B, and C'), Intl.Collator (locale-aware string sorting), Intl.PluralRules (correct pluralisation per locale), and Intl.Segmenter (word/sentence boundaries). All major browsers support it. It handles locale-specific rules like Arabic RTL, German ordinal numbers, Japanese date formats, and Indian number grouping.

Common Misconception

You need a library like moment.js or date-fns for locale-aware formatting — the built-in Intl API handles most formatting needs natively with no dependencies.

Why It Matters

Hardcoded date and number formats break for international users — Intl.DateTimeFormat and Intl.NumberFormat automatically apply the user's locale conventions with no extra code.

Common Mistakes

  • Creating a new Intl.NumberFormat on every call in a loop — formatters are expensive to construct; cache them.
  • Not using navigator.language for the user's locale — hardcoding 'en-US' breaks for international users.
  • Using Intl.RelativeTimeFormat without specifying the unit — 'days', 'hours' must be explicit.
  • Forgetting Intl.Collator for sorting strings — standard < operator gives wrong order for accented characters.

Code Examples

✗ Vulnerable
// Manual formatting — locale-unaware:
const price = '$' + amount.toFixed(2); // Wrong for non-US users
const date = month + '/' + day + '/' + year; // Ambiguous internationally

// Wrong sort order for accented chars:
words.sort((a, b) => a < b ? -1 : 1); // Wrong for 'café' vs 'can'
✓ Fixed
// Intl API — automatic locale handling:
const price = new Intl.NumberFormat(navigator.language, {
    style: 'currency', currency: 'USD'
}).format(amount); // '1,234.56' (US) or '1.234,56 $' (DE)

const date = new Intl.DateTimeFormat(navigator.language, {
    year: 'numeric', month: 'long', day: 'numeric'
}).format(new Date()); // 'March 16, 2026' or '16. März 2026'

const relative = new Intl.RelativeTimeFormat(navigator.language)
    .format(-2, 'day'); // '2 days ago' or 'il y a 2 jours'

words.sort(new Intl.Collator(navigator.language).compare); // Correct sort

Added 16 Mar 2026
Edited 22 Mar 2026
Views 86
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
2 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 1 ping M 0 pings T 0 pings W 2 pings T 2 pings F 0 pings S 1 ping S 0 pings M 0 pings T 1 ping W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 1 ping F
Applebot 1
Bing 1
Google 10 Amazonbot 9 Perplexity 9 Ahrefs 5 ChatGPT 4 SEMrush 4 PetalBot 4 Unknown AI 3 Scrapy 3 Claude 2 Majestic 1 Meta AI 1 Twitter/X 1 Bing 1 Applebot 1
crawler 51 crawler_json 5 pre-tracking 2
🧱 FUNDAMENTALS — new to this? Start with the ground floor.
JavaScript javascript The programming language of the browser — it reads and modifies the page (the DOM), reacts to user events, and fetches data without reloading.

JavaScript is the only language browsers execute, so every interactive behaviour on the web goes through it. Its two defining traits — single-threaded event loop and loose typing (== coercion) — explain the majority of both its bugs and its design patterns.

💡 Default to const, use === always, and reach for let only when a value genuinely reassigns.

Ask Codex about JavaScript →
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Low
⚡ Quick Fix
Use Intl.NumberFormat, Intl.DateTimeFormat, and Intl.RelativeTimeFormat for all user-facing numbers, dates, and relative times — they respect the user's locale without any library
📦 Applies To
javascript ES2015 web cli
🔗 Prerequisites
🔍 Detection Hints
Hardcoded date format strings; new Date().toLocaleDateString() without locale; manual currency formatting with .toFixed(2)
Auto-detectable: ✗ No eslint typescript
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Low ✓ Auto-fixable Fix: Low Context: Function


✓ schema.org compliant