JS Intl API Guide

Welcome to the Interactive Intl Guide

The `Intl` object is the namespace for the ECMAScript Internationalization API (ECMA-402). It's a powerful part of JavaScript for language-sensitive operations like string comparison, number formatting, and date/time formatting. This guide provides an interactive playground to explore its features.

How to use this guide: Select an API from the navigation on the left. Each section provides a live playground. Change the inputs, locales, and options to see how the output changes in real time. This hands-on approach is the best way to learn!

Further Reading & Official Documentation

For a deeper dive and the official specification, refer to these essential resources:

Core Concepts

Almost all `Intl` constructors share a common signature: `new Intl.Constructor(locales, options)`.

  • `locales`: A string or array of strings representing BCP 47 language tags (e.g., "en-US", "de-DE"). The environment picks the best-supported locale.
  • `options`: An object with configuration properties specific to the constructor.

What are BCP 47 Language Tags?

A BCP 47 language tag is a standardized code used to identify human languages. "BCP" stands for "Best Current Practice," and this standard ensures different systems can reliably understand which language and regional conventions to use.

The tags are built from smaller pieces called "subtags," separated by hyphens. The most common are:

  • Language: A required two or three-letter code (e.g., en for English, es for Spanish).
  • Script (Optional): A four-letter code for the writing system (e.g., Hans for Simplified Chinese script).
  • Region (Optional): A two-letter country code (e.g., US for the United States, GB for Great Britain).

Examples:

  • en-US: English (en) as used in the United States (US).
  • es-CL: Spanish (es) as used in Chile (CL).
  • zh-Hans-CN: Chinese (zh), written in the Simplified (Hans) script, as used in mainland China (CN).

These tags allow the Intl API to apply specific regional formats for dates, numbers, currencies, and sorting rules.