Regex & Text

JavaScript String Length

JavaScript .length counts UTF-16 code units. That is useful for runtime behavior, but it is not always the number of Unicode code points, visible characters, or encoded bytes.

Published

Live metric comparison

Try a string

Edit the text or choose a preset. The four values are calculated by the same shared logic as String Length Calculator.

JavaScript .length2UTF-16 code units
Unicode code points1Unicode values
Visible graphemes1User-perceived characters
UTF-8 bytes4Encoded byte size

Result → explanation

Why the counts differ

.length

Counts UTF-16 code units used by JavaScript strings.

Code points

Count Unicode scalar values, but not necessarily visible characters.

Graphemes

Approximate the characters a user perceives on screen.

UTF-8 bytes

Measure encoded payload or storage size.

Choose the metric you need

MetricAPIUseful for
UTF-16 unitsvalue.lengthJavaScript and DOM limits
Code points[...value].lengthUnicode scalar values
GraphemesIntl.SegmenterVisible-character limits
UTF-8 bytesTextEncoderPayload and storage size

Practice with the full tool

Measure your own string

Compare JavaScript length, Unicode code points, graphemes and UTF-8 bytes with your own input.

Continue in String Length Calculator →