Javascript String Length

Introduction

The length of any string can be returned by using the length property:

let text = "This is the letter sigma: \u03a3."; 
console.log(text.length); 

This property returns the number of 16-bit characters in the string.

If a string contains double-byte characters, the length property may not accurately return the number of characters.


let myString = "Hello World";

console.log(myString.length);    // "11"
console.log("Hello World".length);    // "11"



PreviousNext

Related