# Unicode

> The Unicode is a standard that assigns a unique number to every character of every writing system.

## What is Unicode?

The standard that gives every character, from Latin letters to emoji, a unique code point. One visible character can consist of several code points, so string length and slicing in code do not always match what users see.

- Topic: Internationalization
- Type: concept

## Example

Wrong:

```js
const text = '👍🏽 ok';
const count = text.length; // 7
```

Right:

```js
const text = '👍🏽 ok';
const segmenter = new Intl.Segmenter();
const count = [...segmenter.segment(text)].length; // 4
```

`length` counts UTF-16 code units; `Intl.Segmenter` counts the characters a user actually sees.

## Common mistakes

- Cutting a string with `slice()` and breaking an emoji or accented letter in half.

## Key points

- Text is split into user-visible characters with `Intl.Segmenter`, not by indexes, when truncating or counting.
- Strings are compared after `normalize()` when they come from different sources.

## Interview questions

### What is the difference between Unicode and UTF-8?

Unicode assigns a number to each character; UTF-8 is one way to store those numbers as bytes.

### Why does an emoji have a length of 2 in JavaScript?

JavaScript strings are UTF-16, and characters outside the basic range take two code units, called a surrogate pair.

### What is a code point?

The unique number Unicode gives a character, written like 'U+00E9' for 'é'. Some visible characters combine several code points.

## Related cards

- [UTF-8](https://wonderium.dev/web/utf-8.md)
- [Intl.Segmenter](https://wonderium.dev/js/intl-segmenter.md)
- [.normalize()](https://wonderium.dev/js/string-normalize.md)
- [string](https://wonderium.dev/js/string-type.md)

---

- Level: [Web Platform](https://wonderium.dev/web.md)
- HTML version: https://wonderium.dev/web/unicode
- Last updated: 2026-11-25
