What is resolvedOptions()?
The resolvedOptions() method is available on all Intl formatter objects created through the Internationalization API. When you instantiate an Intl formatter, you provide a locale identifier and optional configuration options. The JavaScript runtime performs locale negotiation, potentially substituting your requested locale with the best available match and applying default values for options you didn't specify. The resolvedOptions() method returns an object containing the actual values that were resolved after this process.
For developers building internationalized web applications, understanding this method is essential for debugging locale issues and ensuring consistent user experiences across different languages and regions.
Core Behavior
The resolvedOptions() method operates identically across all Intl formatters in terms of its basic behavior - it returns an object reflecting the computed options. However, the specific properties included in that object vary depending on which formatter you created. This is because each formatter type has its own set of configuration options relevant to its purpose.
const formatter = new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'USD' });
const options = formatter.resolvedOptions();
console.log(options.locale); // "de-DE"
console.log(options.style); // "currency"
console.log(options.currency); // "USD"
- Returns a new object with the resolved configuration options
- Available on Intl.NumberFormat, Intl.DateTimeFormat, Intl.Collator, and other Intl formatters
- Takes no parameters - just call it on your formatter instance
- Reflects the effective options after locale negotiation
According to the MDN Web Docs documentation on the Intl API, this method provides transparency into how JavaScript handles locale resolution, which is essential for debugging internationalization issues and building adaptive user interfaces.
Intl.Collator and resolvedOptions()
The Intl.Collator constructor creates objects that compare strings according to locale-specific rules. This is essential for sorting arrays of strings in ways that make sense for different languages - for example, handling accented characters, different alphabet orders, and special collation rules.
When working on global web applications, proper string sorting in different languages becomes a critical feature for user experience.
Key Properties
When you call resolvedOptions() on a Collator, you'll see these properties:
- locale: The BCP 47 language tag for the locale actually used
- usage: Either "sort" for sorting or "search" for searching
- sensitivity: How differences are treated ("base", "accent", "case", or "variant")
- ignorePunctuation: Whether punctuation is considered in comparisons
- collation: The collation type for this locale
- numeric: Whether numeric sorting is enabled
- caseFirst: Whether uppercase or lowercase comes first
Practical Example
// Create a Collator for German sorting
const collator = new Intl.Collator('de-DE', {
sensitivity: 'base',
usage: 'sort',
numeric: true
});
const options = collator.resolvedOptions();
console.log(options.locale); // "de-DE"
console.log(options.usage); // "sort"
console.log(options.sensitivity); // "base"
console.log(options.numeric); // true
The sensitivity property controls what differences matter when comparing strings. A sensitivity of "base" ignores case and accents, so "a" equals "A" equals "à". The numeric option enables natural sorting where "file10" comes after "file2".
As documented in the MDN Intl.Collator reference, these properties help you understand exactly how your string comparisons are configured, which is crucial for debugging sorting issues in internationalized applications.
Intl.DateTimeFormat and Timezone Detection
One of the most common uses for resolvedOptions() is discovering what timezone a DateTimeFormatter is using. When you create a DateTimeFormat without explicitly specifying a timeZone, it defaults to the runtime's default time zone.
For applications serving users across multiple regions, implementing robust timezone handling ensures that date and time displays are accurate for each user's location.
Key Properties
- locale: The BCP 47 language tag for the locale actually used
- calendar: The calendar type (e.g., "gregory", "japanese", "chinese")
- numberingSystem: The digit set being used (e.g., "latn", "arab", "hanidec")
- timeZone: The IANA timezone name (e.g., "America/New_York")
- hourCycle: The hour cycle ("h11", "h12", "h23", "h24")
- hour12: Calculated from hourCycle
- weekday, era, year, month, day: Date component styles
- hour, minute, second: Time component styles
Timezone Detection Example
// Create a formatter to discover the default timezone
const formatter = new Intl.DateTimeFormat();
const options = formatter.resolvedOptions();
console.log(options.timeZone); // e.g., "America/New_York" or "Europe/London"
console.log(options.locale); // e.g., "en-US"
console.log(options.calendar); // e.g., "gregory"
The Intl.DateTimeFormat.resolvedOptions().timeZone property returns the IANA timezone identifier. This is valuable for applications that need to display times in the user's local timezone.
Explicit Timezone Configuration
// Specify a timezone explicitly
const formatter = new Intl.DateTimeFormat('en-US', {
timeZone: 'America/Los_Angeles',
timeZoneName: 'long'
});
const options = formatter.resolvedOptions();
console.log(options.timeZone); // "America/Los_Angeles"
console.log(options.timeZoneName); // "long"
const date = new Date('2025-01-15T12:00:00Z');
console.log(formatter.format(date)); // "January 15, 2025 at 10:00:00 AM PST"
According to the MDN Intl.DateTimeFormat documentation, the formatter canonicalizes timezone names to their official IANA identifiers, ensuring consistency across different environments.
Intl.NumberFormat and Percent Formatting
The Intl.NumberFormat constructor creates objects for formatting numbers according to locale-specific conventions. The resolvedOptions() method reveals the specific formatting style that was applied.
Building modern web applications with proper number formatting improves usability for international audiences.
Key Properties
- locale: The BCP 47 language tag for the locale actually used
- numberingSystem: The digit set being used
- style: "decimal", "percent", "currency", or "unit"
- currency: ISO 4217 currency code (only when style is "currency")
- currencyDisplay: How currency is shown ("symbol", "code", "name", "narrowSymbol")
- currencySign: "standard" or "accounting"
- minimumFractionDigits, maximumFractionDigits: Decimal precision
- useGrouping: Whether thousands separators are shown
Percent Formatting Example
// Format a number as a percentage
const percentFormatter = new Intl.NumberFormat('en-US', {
style: 'percent',
minimumFractionDigits: 1,
maximumFractionDigits: 1
});
const options = percentFormatter.resolvedOptions();
console.log(options.style); // "percent"
console.log(options.minimumFractionDigits); // 1
console.log(options.maximumFractionDigits); // 1
console.log(percentFormatter.format(0.25)); // "25.0%"
console.log(percentFormatter.format(0.125)); // "12.5%"
Currency Formatting
// Format numbers as US dollars
const currencyFormatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
currencyDisplay: 'symbol'
});
const options = currencyFormatter.resolvedOptions();
console.log(options.style); // "currency"
console.log(options.currency); // "USD"
console.log(options.currencyDisplay); // "symbol"
console.log(currencyFormatter.format(99.99)); // "$99.99"
console.log(currencyFormatter.format(1000)); // "$1,000.00"
As documented in the MDN Intl.NumberFormat reference, the resolved options confirm the complete configuration for your number formatter, including decimal precision settings and currency display preferences.
Common Patterns and Best Practices
Understanding resolvedOptions() helps you write more robust internationalization code. By inspecting what your formatters actually resolved, you can detect configuration issues early and ensure consistent behavior.
For enterprise applications requiring comprehensive internationalization, working with experienced web development teams ensures proper implementation from the start.
Configuration Verification
Before displaying formatted data, verify that your formatter is configured as expected:
function createVerifiedFormatter(locale, options) {
const formatter = new Intl.NumberFormat(locale, options);
const resolved = formatter.resolvedOptions();
if (options.style === 'currency' && resolved.currency !== options.currency) {
console.warn(`Currency ${options.currency} not available, using ${resolved.currency}`);
}
return formatter;
}
const formatter = createVerifiedFormatter('en-US', {
style: 'currency',
currency: 'EUR'
});
Adaptive Formatting
The resolved options can inform how you display formatted data:
function formatTemperature(celsius, locale) {
const formatter = new Intl.NumberFormat(locale, {
style: 'unit',
unit: 'celsius',
unitDisplay: 'short'
});
const options = formatter.resolvedOptions();
return formatter.format(celsius);
}
console.log(formatTemperature(25, 'en-US')); // "25°C"
console.log(formatTemperature(25, 'fr-FR')); // "25 °C"
This pattern ensures that your application gracefully handles situations where the requested locale or options aren't fully supported.
Summary
The resolvedOptions() method is a powerful tool for inspecting and debugging your Intl formatter configuration. It reveals the actual values after locale negotiation, helping you build more robust, internationally-aware applications. Whether you're formatting dates, numbers, or text, understanding what your formatters actually resolved gives you confidence in your internationalization implementation.
Frequently Asked Questions
What formatters support resolvedOptions()?
All Intl formatters support resolvedOptions(), including Intl.NumberFormat, Intl.DateTimeFormat, Intl.Collator, Intl.ListFormat, Intl.RelativeTimeFormat, and Intl.Segmenter.
Why does resolvedOptions() return a different locale than I requested?
JavaScript performs locale negotiation when creating formatters. If the requested locale isn't available, it selects the best supported match. The resolved locale is the authoritative result of this process.
How do I get the user's timezone?
Create an Intl.DateTimeFormat without specifying a timeZone, then call resolvedOptions().timeZone to see the runtime's default timezone.
Does resolvedOptions() return all possible properties?
No. resolvedOptions() only returns properties relevant to the formatter type and options you specified. For example, currency properties only appear when style is "currency".