JavaScript (ES2026) reference · String Methods

JavaScript String length Property

The number of UTF-16 code units in the string, which is more than the number of characters for emoji.

JavaScript (ES2026) Since ES1

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

string.length

Return value

A non-negative integer.

Examples

Length in code unitsTry it yourself
console.log("camel".length, "".length, "\u{1F42B}".length);

Output

5 0 2
Counting charactersTry it yourself
const text = "hi \u{1F42B}";
console.log(text.length, [...text].length); // code units vs characters

Output

5 4

Version history

VersionChange
JavaScript ES1Added

In other languages

Was this page helpful?