Skip to tool

JavaScript String.length Online

Count JavaScript UTF-16 code units and compare the UTF-8 byte count.

The output updates as you type. The tool processes input in your browser.

Worked example

A visual character can contain multiple Unicode code points. Compare the text length and UTF-8 byte count when validating a storage limit.

Sample input
A😀
Sample output
3

JavaScript example

console.log("A😀".length);
Expected native output
3

Using this operation in JavaScript

The interactive result uses JavaScript. JavaScript string indexes count UTF-16 code units. Use code-point iteration when working with supplementary Unicode characters.

JavaScript reference