String Length

Finding the length of a string.

Examples

Basic Length

Getting the number of characters in a string.

let text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let length = text.length;
console.log(length); // 26

Empty String

Length of an empty string.

let str = "";
console.log(str.length); // 0

Length with Spaces

Spaces are counted as characters.

let str = "Hello World";
console.log(str.length); // 11

Test Your Knowledge

JavaScript Quiz

No quiz available for this topic yet.