Resolving Locale and Options
You'll learn how to discover the actual locale and settings that Intl formatters applied after negotiation.
Why Resolution Matters
When you create an Intl.NumberFormat or Intl.DateTimeFormat, you might request a specific locale like "en-US" or pass various options. But the JavaScript engine performs locale negotiation—it picks the best available locale based on what you requested and what the system supports. Sometimes the final settings differ from what you asked for.
The resolvedOptions() method reveals what the formatter actually ended up using.
Using resolvedOptions()
Every Intl formatter has a resolvedOptions() method that returns an object showing the resolved configuration:
const formatter = new Intl.DateTimeFormat('en-US', {
timeZone: 'America/New_York',
hour: 'numeric',
minute: 'numeric'
});
const resolved = formatter.resolvedOptions();
console.log(resolved);
// {
// locale: 'en-US',
// timeZone: 'America/New_York',
// hour: 'numeric',
// minute: 'numeric',
// hour12: true, // <- Automatically added!
// ...
// }
Notice hour12: true appeared even though you didn't specify it—the formatter inferred it from the en-US locale.
When to Use It
Use resolvedOptions() when you need to:
- Debug why formatting looks unexpected
- Verify which locale was actually selected
- Check default options the engine added
- Ensure timezone or currency codes were accepted
Key Takeaway: Use resolvedOptions() to inspect the actual locale and settings applied by Intl formatters after locale negotiation, revealing both your explicit options and engine-added defaults.