ResolvedOptions to Inspect Settings
You'll learn how to use resolvedOptions() to discover what formatting settings are actually being used after the Intl API applies defaults and resolves ambiguities.
What Problem Does This Solve?
When you create an Intl.DateTimeFormat or Intl.NumberFormat instance, you often don't specify every option explicitly. The Intl API fills in defaults based on the locale, applies fallbacks, and resolves conflicts. But what values did it actually choose?
The resolvedOptions() method returns an object containing all the final settings used by the formatter—think of it as "peeking under the hood" to see exactly how your data will be formatted.
How It Works
Call resolvedOptions() on any Intl.DateTimeFormat or Intl.NumberFormat instance to get a plain object with every option it's using:
const dtf = new Intl.DateTimeFormat('en-US', {
month: 'long',
timeZone: 'America/New_York'
});
const options = dtf.resolvedOptions();
console.log(options.locale); // "en-US"
console.log(options.timeZone); // "America/New_York"
console.log(options.month); // "long"
console.log(options.calendar); // "gregory" (default applied)
Even though you didn't specify calendar, it's in the resolved options because the Intl API chose a default.
Why This Matters
- Debugging: Confirm your locale or time zone was recognized correctly
- Documentation: Log actual settings for auditing or troubleshooting
- Dynamic behavior: Adjust logic based on which defaults were applied
Key Takeaway:
resolvedOptions() reveals the complete, final configuration of an Intl formatter after all defaults and resolution logic have been applied—essential for understanding and debugging internationalization behavior.